Image Sizes

P

p byers

Hello Folks,

I have a WebSite that allows clients to upload 'ImageFiles'

They are restricted to .JPG, .GIF and .PNG and a size of 100Kb.

I have a page that will show the Images. The size is to be restricted.

If the image height and width is less than the restricted size, the
image is just centred in the 'Restricted Area'.

If the image height or width is greater than the restricted size, the
"IMG" tag has "height" & "width" parameters to contain it into the
"Restricted Area".

At the momement, the image size is obtained by the use of ServerObjects
ASPImage Active X object.


I need to put a copy of the page onto a server that does not have
ASPImage installed.

Is there any way I can get Image Width and Height without any special
Active X 'es ??

Thank you
Pete (Northolt UK)
 
M

Mike Brind

p byers said:
Hello Folks,

I have a WebSite that allows clients to upload 'ImageFiles'

They are restricted to .JPG, .GIF and .PNG and a size of 100Kb.

I have a page that will show the Images. The size is to be restricted.

If the image height and width is less than the restricted size, the
image is just centred in the 'Restricted Area'.

If the image height or width is greater than the restricted size, the
"IMG" tag has "height" & "width" parameters to contain it into the
"Restricted Area".

At the momement, the image size is obtained by the use of ServerObjects
ASPImage Active X object.


I need to put a copy of the page onto a server that does not have
ASPImage installed.

Is there any way I can get Image Width and Height without any special
Active X 'es ??

Not unless you can use ASP.NET for that page.
 
R

Roger

p byers said:
Hello Folks,

I have a WebSite that allows clients to upload 'ImageFiles'

They are restricted to .JPG, .GIF and .PNG and a size of 100Kb.

I have a page that will show the Images. The size is to be restricted.

If the image height and width is less than the restricted size, the
image is just centred in the 'Restricted Area'.

If the image height or width is greater than the restricted size, the
"IMG" tag has "height" & "width" parameters to contain it into the
"Restricted Area".

At the momement, the image size is obtained by the use of ServerObjects
ASPImage Active X object.


I need to put a copy of the page onto a server that does not have
ASPImage installed.

Is there any way I can get Image Width and Height without any special
Active X 'es ??

Thank you
Pete (Northolt UK)

Hi Pete,

I have an old bit of code which works for jpg and gif...

set i = loadpicture(server.mappath(whatever))
owidth = round(i.width / 26.4583)
oheight = round(i.height / 26.4583)

I don't recall why I had to divide by 26.4583, and it does need write
permission on the file - or folder(?).

For png the width + height seems to be bytes 16-20 and 21-24 (but check the
spec, this code is ancient)
so you can do...

set o = server.CreateObject("ADODB.Stream")
set fso = server.CreateObject("Scripting.FileSystemObject")
set ff = fso.GetFile(server.mappath(f))
o.Type = 1
o_Open
o.LoadFromFile(server.mappath(f))
select case ff.type
case "PNG Image"
scanimg 24, 20, 24

where scanimg is...

function scanimg(f,w,h)
dim s

s = o.Read(f)
if lenb(s) = f then
owidth = clng(ascb(midb(s, w, 1)) + ((ascb(midb(s, w - 1, 1)) * 256)))
oheight = clng(ascb(midb(s, h, 1)) + ((ascb(midb(s, h - 1, 1)) * 256)))
end if

end function

That code only looks at two bytes rather than four, but you can see the
idea.

You can do similar things with bitmap, tif, gif, but jpeg is a right pain in
the arse.

Roger
 
P

p byers

Thanks for your reply
Hi Pete,

I have an old bit of code which works for jpg and gif...

set i = loadpicture(server.mappath(whatever))
owidth = round(i.width / 26.4583)
oheight = round(i.height / 26.4583)

I don't recall why I had to divide by 26.4583, and it does need write
permission on the file - or folder(?).

For png the width + height seems to be bytes 16-20 and 21-24 (but check the
spec, this code is ancient)
so you can do...

set o = server.CreateObject("ADODB.Stream")
set fso = server.CreateObject("Scripting.FileSystemObject")
set ff = fso.GetFile(server.mappath(f))
o.Type = 1
o_Open
o.LoadFromFile(server.mappath(f))
select case ff.type
case "PNG Image"
scanimg 24, 20, 24

where scanimg is...

function scanimg(f,w,h)
dim s

s = o.Read(f)
if lenb(s) = f then
owidth = clng(ascb(midb(s, w, 1)) + ((ascb(midb(s, w - 1, 1)) * 256)))
oheight = clng(ascb(midb(s, h, 1)) + ((ascb(midb(s, h - 1, 1)) * 256)))
end if

end function

That code only looks at two bytes rather than four, but you can see the
idea.

You can do similar things with bitmap, tif, gif, but jpeg is a right pain in
the arse.

Roger
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top