JPG and GIF images

darkforcesjedi
06-17-2002, 07:07 PM
I'd like to be able to detemine the width and height of GIF and JPG images stored on the hard disk of the server (e.g. "c:\inetpub\wwwroot\asp\image.jpg"). Does anyone know how this is done? I believe the 7th and 8th bytes represent the width in a GIF file and the 9th and 10th, the height. I don't know about JPG's.

Rezner
06-17-2002, 07:30 PM
Here (http://abstractvb.com/code.asp?F=50&P=1&A=829) is an example for how to do this with VB. You can easily modify to work with ASP.

darkforcesjedi
06-17-2002, 07:39 PM
Looks like it works. Thanks. If anyone cares for the functions, here they are:


Function GifRead(filepath) ' Returns "width,height"
set fso1=server.createobject("scripting.filesystemobject")
set img=fso1.opentextfile(filepath,1)
tmp = img.read(6)
widthbytes = img.Read(2)
width = clng(asc(left(widthbytes, 1)) + ((asc(right(widthbytes, 1)) * 256)))
heightbytes = img.Read(2)
height = clng(asc(left(heightbytes, 1)) + ((asc(right(heightbytes, 1)) * 256)))
img.close
set fso1=nothing
set img=nothing

GifRead = width & "," & height
end function


Function JpgRead(filepath) ' Returns "width,height"
set fso1=server.createobject("scripting.filesystemobject")
set img=fso1.opentextfile(filepath,1)
tmp = img.read(163)
heightbytes = img.Read(2)
height = clng(asc(right(heightbytes, 1)) + ((asc(left(heightbytes, 1)) * 256)))
widthbytes = img.Read(2)
width = clng(asc(right(widthbytes, 1)) + ((asc(left(widthbytes, 1)) * 256)))
img.close
set fso1=nothing
set img=nothing

JpgRead = width & "," & height
end function

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum