0

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?

Reger
  • 474
  • 4
  • 17
Arif
  • 1,222
  • 6
  • 29
  • 60
  • 1
    Resize the height the same value you resize the width. If height is still >150 then resize both again. I hope I understood you correctly. – Sbls Feb 15 '14 at 12:21
  • Hi try to below link may be help you http://stackoverflow.com/questions/18805497/php-resize-image-on-upload/39386636#39386636 – Pankaj Upadhyay Sep 08 '16 at 09:02

1 Answers1

2

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;
}
Reger
  • 474
  • 4
  • 17