Question

I have a file upload form where I upload only jpg, png and gif images. I resize the image if its width is more then 225 and height automatically fix with that width.

if($width > 225) {
    $newwidth = 225;
} 
else {
    $newwidth = $width; 
}
$newheight = ($height/$width)*$newwidth;

The above code fixes the width for me in case if image > 225. Now the problem is that the new height is according to the image width. I don't want the height to be more then 150. How can I fix it with out stretching the image?

Was it helpful?

Solution

Try adjusting the width in case of $newheight being greater than 150, calculating the proportion. Add this at the bottom:

if ($newheight > 150) {
    $proportion = $newwidth/$newheight;
    $newheight = 150;
    $newwidth = 150*$proportion;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top