Reputation: 15
I am currently using the following code to re size all images bigger than 800 x600 to the required size.
if (($width>800) and ($height>600))
{
WideImage::load($img_path.$name)->resize(800, 600)->saveToFile($img_path.$name);
}
However this won't work if for example an image has a width of 1024 and height 559
I can use an or but I am not sure how to deal with resizing those Images .
Upvotes: 0
Views: 73
Reputation: 33512
I have always found the most reliable method to resize an image is to use a ratio of the height to the width.
The psuedocode code would look like this:
$widthRatio=$originalImageHeight/$originalImageWidth;
$newImage=resize(800, 800*$widthRatio);
This will then resize it to be 800 while maintaining the original ratio.
Also, you might want to set or at least check the ratio so that you don't get an image that is 1000 x 20,000 uploaded which will still mess up your site if you resize it to 800 x 16,000
Upvotes: 1