webForumDet fria alternativet

ta reda på bildstorlek

ASP

7 svar · 268 visningar · startad av visslaren

Medlem sedan juli 20011 222 inlägg
Frågan#1

Jag skulle behöva lite hjälp. Det är så att jag måste fixa ihop ett script som tar reda på måtten på en bild hämtad ur en databas. Jag har sökt här på forumet och hittat ett script som tydligen ska fixa fram info om bild men jag får det inte att fungera. jag får fel på rad 80; " Ogiltigt proceduranrop eller argument.: 'asc' " Jag har markerat rad 80 i scriptet nedanför.
Jag är inte alltför insatt i asp ännu och jag har tidspress på mig så jag har för tillfället inte tid att sätta mig ner och gå inpå djupet :( Så jag skulle behöva lite hjälp med få igång scriptet.

Tack på förhand.

scriptet:

	function GetBytes(flnm, offset, bytes)

     Dim objFSO
     Dim objFTemp
     Dim objTextStream
     Dim lngSize

     on error resume next

     Set objFSO = CreateObject("Scripting.FileSystemObject")
     
     ' First, we get the filesize
     Set objFTemp = objFSO.GetFile(flnm)
     lngSize = objFTemp.Size
     set objFTemp = nothing

     fsoForReading = 1
     Set objTextStream = objFSO.OpenTextFile(flnm, fsoForReading)

     if offset > 0 then
        strBuff = objTextStream.Read(offset - 1)
     end if

     if bytes = -1 then		' Get All!

        GetBytes = objTextStream.Read(lngSize)  'ReadAll

     else

        GetBytes = objTextStream.Read(bytes)

     end if

     objTextStream.Close
     set objTextStream = nothing
     set objFSO = nothing

  end function

  function lngConvert(strTemp)
     lngConvert = clng(asc(left(strTemp, 1)) + ((asc(right(strTemp, 1)) * 256)))
  end function

  function lngConvert2(strTemp)
     lngConvert2 = clng(asc(right(strTemp, 1)) + ((asc(left(strTemp, 1)) * 256))) <== rad 80
  end function

  function gfxSpex(flnm, width, height, depth, strImageType)

     dim strPNG 
     dim strGIF
     dim strBMP
     dim strType
     strType = ""
     strImageType = "(unknown)"

     gfxSpex = False

     strPNG = chr(137) & chr(80) & chr(78)
     strGIF = "GIF"
     strBMP = chr(66) & chr(77)

     strType = GetBytes(flnm, 0, 3)

     if strType = strGIF then				

        strImageType = "GIF"
        Width = lngConvert(GetBytes(flnm, 7, 2))
        Height = lngConvert(GetBytes(flnm, 9, 2))
        Depth = 2 ^ ((asc(GetBytes(flnm, 11, 1)) and 7) + 1)
        gfxSpex = True

     

     else

        strBuff = GetBytes(flnm, 0, -1)		
        lngSize = len(strBuff)
        flgFound = 0

        strTarget = chr(255) & chr(216) & chr(255)
        flgFound = instr(strBuff, strTarget)

        if flgFound = 0 then
           exit function
        end if

        strImageType = "JPG"
        lngPos = flgFound + 2
        ExitLoop = false

        do while ExitLoop = False and lngPos < lngSize

           do while asc(mid(strBuff, lngPos, 1)) = 255 and lngPos < lngSize
              lngPos = lngPos + 1
           loop

           if asc(mid(strBuff, lngPos, 1)) < 192 or asc(mid(strBuff, lngPos, 1)) > 195 then
              lngMarkerSize = lngConvert2(mid(strBuff, lngPos + 1, 2))
              lngPos = lngPos + lngMarkerSize  + 1
           else
              ExitLoop = True
           end if

       loop
       '
       if ExitLoop = False then

          Width = -1
          Height = -1
          Depth = -1

       else

          Height = lngConvert2(mid(strBuff, lngPos + 4, 2))
          Width = lngConvert2(mid(strBuff, lngPos + 6, 2))
          Depth = 2 ^ (asc(mid(strBuff, lngPos + 8, 1)) * 8)
          gfxSpex = True

       end if
                   
     end if

  end function

sub test(flnm)

if right(flnm, 3)="gif" then
        Width = lngConvert(GetBytes(flnm, 7, 2))
        Height = lngConvert(GetBytes(flnm, 9, 2))
        Depth = 2 ^ ((asc(GetBytes(flnm, 11, 1)) and 7) + 1)

     else

        strBuff = GetBytes(flnm, 0, -1)		
        lngSize = len(strBuff)
        flgFound = 0

        strTarget = chr(255) & chr(216) & chr(255)
        flgFound = instr(strBuff, strTarget)

        strImageType = "JPG"
        lngPos = flgFound + 2
        ExitLoop = false

        do while ExitLoop = False and lngPos < lngSize

           do while asc(mid(strBuff, lngPos, 1)) = 255 and lngPos < lngSize
              lngPos = lngPos + 1
           loop

           if asc(mid(strBuff, lngPos, 1)) < 192 or asc(mid(strBuff, lngPos, 1)) > 195 then
              lngMarkerSize = lngConvert2(mid(strBuff, lngPos + 1, 2))
              lngPos = lngPos + lngMarkerSize  + 1
           else
              ExitLoop = True
           end if

       loop
    
       if ExitLoop = "False" then
          Width = -1
          Height = -1
          Depth = -1
      else
          Height = lngConvert2(mid(strBuff, lngPos + 4, 2))
          Width = lngConvert2(mid(strBuff, lngPos + 6, 2))
          Depth = 2 ^ (asc(mid(strBuff, lngPos + 8, 1)) * 8)
       end if
                   

end if
	a=width
	b=height
	
end sub
Medlem sedan sep. 20026 425 inlägg
#2

Fel forum. :( Klick.

Medlem sedan juni 200032 967 inlägg
#3

m_soderlund skrev:

Fel forum. :( Klick.

Nej, inte fel forum, men däremot fel kod-markering. Använd [php]-taggarna till php-kod, men till asp-kod förstörs bara läsbarheten.

Medlem sedan sep. 20026 425 inlägg
#4

@nders skrev:

m_soderlund skrev:

Fel forum. :( Klick.

Nej, inte fel forum, men däremot fel kod-markering. Använd [php]-taggarna till php-kod, men till asp-kod förstörs bara läsbarheten.

Oooops, ledsen. Tusan - han rapportera det till moderatorn också.. :x

Medlem sedan feb. 200112 078 inlägg
#5

Men moderatorn är här och läser alla inlägg ändå, så.. ;)

Tråden stannar alltså.

Medlem sedan juli 20011 222 inlägg
#6

ah ledsen :) gammal vana från phpforumet :)

Medlem sedan juli 20011 222 inlägg
#7

Ingen som kan hjälpa?

Medlem sedan dec. 20003 887 inlägg
#8

Jag ser inte vad som skulle kunna vara fel. Om strBuff är null får du just det felmeddelandet 'Invalid procedurecall...'. Själva funktionen lngConvert2 verkar fungera. Alltså borde det vara strBuff = GetBytes(flnm, 0, -1), som inte gör vad den ska.

260 ms totalt · 4 externa anrop · v20260731065814-full.6fe65c25
123 ms — deklarationer (db)
0 ms — hämta statistik (cache)
133 ms — hämta tråd, inlägg och bilagor (db)
123 ms — ändringar (db)