To maintain the aspect ratio of your original image, calculate the factor by which you have to resize the image in the vertical and horizontal direction.
Example, resize image to 1920 max width or max height
list($width, $height) = getimagesize("your file path"); $ratio = $width / $height; if ($width > $height) { //landscape if ($width > 1920 ) { $full_width = 1920; } else { $full_width = $width; } //set full size $full_height = $full_width / $ratio; $size_full = array($full_width, $full_height); } else { // Portrait if ($height > 1920 ) { $full_height = 1920; } else { $full_height = $width; } //set full size $full_width = $full_height * $ratio; $size_full = array($full_width, $full_height); }
What do you think?