PDA

View Full Version : Image dimensions with ASP


Frank
06-12-2004, 08:19 PM
I needed a way to get the height and width of an image using strictly ASP (not Javascript or third-party components). A quick net search revealed this post over at Developer Fusion:

http://www.developerfusion.com/forums/topic.aspx?id=16878

The relavent code (as posted by the author) is as follows:

<%
dim iWidth, iHeight, iType
sub ImgDimension(img)
dim myImg, fs
Set fs= CreateObject("Scripting.FileSystemObject")
if not fs.fileExists(img) then exit sub
set myImg = loadpicture(img)
iWidth = round(myImg.width / 26.4583)
iHeight = round(myImg.height / 26.4583)
iType = myImg.Type
select case iType
case 0
iType = "None"
case 1
iType = "Bitmap"
case 2
iType = "Metafile"
case 3
iType = "Icon"
case 4
iType = "Win32-enhanced metafile"
end select
set myImg = nothing
end sub

' so if you whant to test it in asp just give the path to your image
ImgDimension(Server.MapPath("../.") & "\images\header.gif")


response.write("Dimensions: " & iWidth & " x " & iHeight & "<br>")
response.write("Image Type: " & iType & "<br>")
%>