Link to home
Start Free TrialLog in
Avatar of ht055
ht055

asked on

image width, height and size

Hi,

How to check the images widht, height and size in asp code?

Please help.

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of zombeen
zombeen

ASPImage is anotyher very good component , used for this + a lot of other things
u shd get that one too from www.serverobjects.com
OR...

Sub getJPEGDimensions(ByVal filename, ByRef width, ByRef height)
     '// sets width and height to the values scooped from the JPEG referenced by filename
     '// Assumes filename supplies a full path (i.e. it has been MapPath'ed)

     Dim lBinPrefix
     Dim lLngStart
     Dim binaryData, objFS, objFile
     
     'filename = Server.MapPath(filename)
     Set objFS = Server.CreateObject("Scripting.FileSystemObject")
     
     Set objFile = objFS.OpenTextFile(filename)
     If Not objFile.AtEndOfStream Then
          binaryData = ChrB(Asc(objFile.Read(1)))
          While Not objFile.AtEndOfStream
                binaryData = binaryData & ChrB(Asc(objFile.Read(1)))
          Wend
     End If
     objFile.Close
     Set objFile = Nothing
     Set objFS = Nothing
     
     
     ' Prefix found before image dimensions          
     lBinPrefix = ChrB(&h00) & ChrB(&h11) & ChrB(&h08)
     
     ' Find the last prefix (so we don't confuse it with data)          
     lLngStart = 1
     Do
          If InStrB(lLngStart, binaryData, lBinPrefix) + 3 = 3 Then Exit Do
          lLngStart = InStrB(lLngStart, binaryData, lBinPrefix) + 3
     Loop
     ' If a prefix was found
     If Not lLngStart = 1 Then
          width = CLng("&h" & HexAt(lLngStart+2, binaryData) & HexAt(lLngStart+3, binaryData))
          height = CLng("&h" & HexAt(lLngStart, binaryData) & HexAt(lLngStart+1, binaryData))
     End If
End Sub


Function HexAt(ByRef pLngPosition, ByRef mStrBinaryData)
     If pLngPosition > LenB(mStrBinaryData) Or pLngPosition <= 0 Then Exit Function
     HexAt = Right("0" & Hex(AscB(MidB(mStrBinaryData, pLngPosition, 1))), 2)
End Function