I have dynamic loaded images wich cannot be larger than 115px. I get them from an external source so I have no control over it.
I could get the image sizes with:
$list = getimagesize($imagePath);
$width = $list[0];
$height = $list[1];
But now I need to resize if they are larger than 115px. Tried this but it didn’t keep the proportion:
$height = round(($height * $width) / $width);
Can someone help me with this?
Thanks in advance.
You should consider using imagecopyresampled or imagecopyresized.
If you’re looking to keep the image scaled properly, you’ll have to throw in a bit more arithmetic, but it shouldn’t be too bad.
Here’s a bit of pseudocode for scaling the image:
Here’s a more generic form for if height and width must be less than 115:
This guarantees that the largest dimension of the image (be it height or width) will be no greater than 115.