QUOTE(joe2kiss @ Jul 5 2005, 10:27 AM)
I'm pretty sure all of you have seen
stock.xchng and the way in which they display their image previews. Well I am trying to accomplish the same results with not much luck.
How is it possible to create thumbnails of a picture and show the preview image scaled down to a smaller size keeping it's original aspect ratio? I've been told to use the
imagex and [ur=http://us3.php.net/manual/en/function.imagesy.php]imagey[/url] functions but have no idea at the kind of calculation I would need to keep the image from getting distorted.
I would like the image to be displayed inside a 400x400px container, but for the image to be scaled down accordingly ... anyone have any ideas on how to do this? Really need help on this one

TIA
[right][snapback]29453[/snapback][/right]
I have never done this but I'll try to help...
This is how I'd approach it.
http://us3.php.net/imagecopyresizedThat's the function that resizes images to the variables you give it.
First make the thumbnail image (not as a physical image but using the GD commands)... Whatever fixed size you're going to have it at... for example 100x100...
Then create a background for the thumbnail in which you have just a solid color behind it (probably black?).
After this, determine which of the two items will be sticks out more (in the case of a square thumbnail it would be the width).
To do this for something like a 120x100 thumbnail (widthxheight) you'd have to do the following (I think).
120/100 - determines the ratio (for this example)
Big Width / Big Height - whatever the image really is.
If the result is greator than 1 the width would stick out more if the result is less than 1 it's the height and equal to 1, it's an actual square.
Ok, after determining which sticks out, you have to set the sticked out side on the image. If it's height that stood out 800x1000 picture, per se, then you set a variable $NewImageHeight equal to 100 (if it were a 100x100 thumbnail) the other variable (for width) would just be equal to the original image height/new image height multipulied by the width (in this example).
After you've determined the width and height of the scaled down image, create the image using imagecopyresized. (Note: this is an entirely different image than the thumbnail we are creating with the width and height created in such a way that it is just a scaled down version.)
After we create this mini-image, you have to determine where you want it on the thumbnail. Most likely you'll want it placed either in the center top position of the image.
I believe the GD library determines the top left corner to be the starting place for an image... so you only really have to find out the width. The way to do this, I think, is to take the new thumb's width and the rescaled image's width and subtract the rescaled from the new thumb's (you don't need to do if they are equal). Then divide the number you get in half and floor() the result. (This would only be necessary in cases where the height is greater than the width of the original image.)
After you do this you simply take the new thumbnail image and you place the new scaled image on it using something like
http://us3.php.net/manual/en/function.imagecopymerge.phpThen you'd be done I think.
This is all just speculation (I've never done this again) but that's how I'd give it a try... Perhaps someone else knows a better way, however... XD
-Tim