class.upload.php is a powerful and mature PHP class to manage uploaded files, and manipulate images in many ways. The script is available under a GPL license.
First I want to say that this is a beautiful script. Thanks for sharing it with us!
For my website I need to resize pictures from all kinds of dimensions to 600 x 270 pixels.
For example: I upload an image with 1162x750 and a image with 824 x 1325 pixels. But both have to be cropped/canvased/resized to fit in 600 x 270 (with their original ratio's). Is this possible with a white background?
I created a image to explain better: http://img238.imageshack.us/img238/6469/questionpe3.jpg (the dimensions in this image are not real)Reply
Try to use image_ratio_crop instead of image_ratio. What is does is to fill the dimensions that you want with the image, keeping the ratio, and cropping the extra parts out.
You can set image_ratio_crop to true, or to a string with one or more from 'TBLR'. If you set it to true, the part of the image which is kept is at the centre of the picture. If you use T,B,L and/or R, you can choose which side or corner of the image is kept while the rest is cropped out.
No, it is not possible to keep the entire image if you want to fill in a precise dimension, and keep the ratio. One elegant way to do that is to use image_ratio_crop, but if you want to keep the image, and fill the rest with a color, you will need something like image_ratio_fill, and a way to set the background color.
It is a good idea, I will probably implement it in the next release.
However, I am not sure it is very wise, since you can just display your pics in a DIV on your page. the DIV can have a fixed dimension, and you center the picture in the DIV. But the feature might be useful in some cases, so I'll add it in.Reply
You probably know it already, but the functions 'imagecopyresampled' and 'imagefill' may help you making the option.
In fact, it is the same option as adjusting the canvas size in Photoshop. Maybe it is nice to also let the user choose which way the canvas has to expand... from center out or only to the left or right.
There are plenty of examples where all images has to be an exact size. In a recent thread, about 60 x 60.... I think it is the same question as mine.
First I want to say that this is a beautiful script. Thanks for sharing it with us!
For my website I need to resize pictures from all kinds of dimensions to 600 x 270 pixels.
For example: I upload an image with 1162x750 and a image with 824 x 1325 pixels. But both have to be cropped/canvased/resized to fit in 600 x 270 (with their original ratio's). Is this possible with a white background?
I created a image to explain better:
http://img238.imageshack.us/img238/6469/questionpe3.jpg
(the dimensions in this image are not real)
same question here.
Anubis, please tell me if you solved this. I need it asap. Thanks.
Try to use image_ratio_crop instead of image_ratio. What is does is to fill the dimensions that you want with the image, keeping the ratio, and cropping the extra parts out.
You can set image_ratio_crop to true, or to a string with one or more from 'TBLR'. If you set it to true, the part of the image which is kept is at the centre of the picture. If you use T,B,L and/or R, you can choose which side or corner of the image is kept while the rest is cropped out.
I modified your picture so it explains how it works if you are to use image_ratio_crop.
See the samples to see examples of image_ratio_crop
So if I understand correctly, it is not possible to keep the entire image? Because that is necessary for my site.
Maybe an idea for the next update???
It is a good idea, I will probably implement it in the next release.
However, I am not sure it is very wise, since you can just display your pics in a DIV on your page. the DIV can have a fixed dimension, and you center the picture in the DIV.
But the feature might be useful in some cases, so I'll add it in.
You probably know it already, but the functions 'imagecopyresampled' and 'imagefill' may help you making the option.
In fact, it is the same option as adjusting the canvas size in Photoshop. Maybe it is nice to also let the user choose which way the canvas has to expand... from center out or only to the left or right.
There are plenty of examples where all images has to be an exact size. In a recent thread, about 60 x 60.... I think it is the same question as mine.
But, thanks for everything!
My point was about the usefulness of doing it, but since it is being asked and seems needed, I will implement it.