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.
Image Constraint
Moderator: General Moderators
-
fractalvibes
- Forum Contributor
- Posts: 335
- Joined: Thu Sep 26, 2002 6:14 pm
- Location: Waco, Texas
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.
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.
-
pootergeist
- Forum Contributor
- Posts: 273
- Joined: Thu Feb 27, 2003 7:22 am
- Location: UK
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.
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
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 ;)