$dims[0]) { // Too wide, scale it down list ($new_width, $new_height) = array($dims[0], $dims[0] / $desired_ratio); } if ($new_height > $dims[1]) { // Too tall, scale it down some more $new_width = min($dims[0], $dims[1] * $desired_ratio); $new_height = $new_width / $desired_ratio; } $new_width = round($new_width); $new_height = round($new_height); Image::factory($input_file) ->crop($new_width, $new_height) ->quality(module::get_var("gallery", "image_quality")) ->save($output_file); } }