ht055
asked on
image width, height and size
Hi,
How to check the images widht, height and size in asp code?
Please help.
Thanks.
How to check the images widht, height and size in asp code?
Please help.
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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("Scrip ting.FileS ystemObjec t")
Set objFile = objFS.OpenTextFile(filenam e)
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(mStrBinaryDa ta, pLngPosition, 1))), 2)
End Function
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("Scrip
Set objFile = objFS.OpenTextFile(filenam
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(mStrBinaryDa
End Function
u shd get that one too from www.serverobjects.com