I need to get some dimensions to display images.
I want to display the image in a maximum pixel-size for the longest side of the image. So, if the maximum length should be 1000px, I have to check if the height or the width is bigger. After that I resize the dimensions in the correct proportions. If the image dimensions are smaller then 1000px, nothing should happen.
This is my solution, which already works. But I don't feel well with it. Is there a smarter solution?
dimensions(1000);
function dimensions($limit) {
if ($width >= $height) {
if ($width < $limit) $limit = $width;
$factor = $width / $limit;
}
else {
if ($height < $limit) $limit = $height;
$factor = $height / $limit;
}
$new_width = $width / $factor;
$new_height = $height / $factor;
}