$image_height && $image_width > $max_width) { $target_width = $max_width; } // Vertical images else if($image_height > $max_width) { $ratio = $image_height / $max_width; $target_width = (int) floor($image_height / $ratio); } else { $target_width = $image_width; } // Resize if($image_width !== $target_width) { $output_image = imagescale($original_image, $target_width); if($output_image === false) throw new Exception(__("Failed to resize image.")); imagedestroy($original_image); } else { $output_image = $original_image; } // Rotate if($rotate_angle) { $output_image = imagerotate($output_image, $rotate_angle, 0); if($output_image === false) throw new Exception(__("Failed to rotate image.")); } // Flip if($is_flipped) { $output_image = imageflip($output_image, IMG_FLIP_HORIZONTAL); if($output_image === false) throw new Exception(__("Failed to flip image.")); } return $output_image; } }