Page 1 of 1
Image Constraint
Posted: Sun Mar 30, 2003 8:39 pm
by fractalvibes
Given that users will upload images of roughly the same size, can anyone point me in the direction of a script or snippet that:
a.) Given that I have an ideal size, say 200W X 300H
b.) Given that the images may be a fair bit larger/smaller/wider/taller
c.) I want to determine the best height and width for the image tag
that is proportional, as close to 200 X 300.
thanks,
Phil J.
Posted: Sun Mar 30, 2003 10:28 pm
by McGruff
I don't have a script but take a look at imagesx() and imagesy() - or getimagesize()
Resizing an image in the browser by setting height and width in html isn't ideal - although it might be good enough for your needs. You either risk getting a blurry mess if you increase the size, or you waste time sending a larger image than you need to the browser if you decrease size.
Posted: Mon Mar 31, 2003 4:12 am
by pootergeist
If you have GD2+ try
http://www.phpclasses.org/browse.html/package/1007.html
if you create a base image of 200px by 300px, then every transformed image will be resized to fit within those dimensions - eg a 600x450 image would become 200x150 thus fitting the 200 width definer with height determined proportionally.
can also add a transformation if you want - eg bevel, drop-shadow, motion-blur, frame, greyscale etc.
basic online demo page unfortunately unaccessible due to server snags.
simple math
Posted: Mon Mar 31, 2003 5:15 am
by d1223m
the maths is quite simple. just look at the width first, scale it to the desired width ( 300 ) remembering the magic scaling number. Then scale the height by the same number if this is greater than the desired height ( 200 ) then you want to determine the scaling number from the height . This way you will get full scaling in at least one direction, which is what you want ;)