$height) { if($width > $max_width) { $width = $max_width; } } else { if($height > $max_width) { $ratio = $height / $max_width; $width = floor($width / $ratio); } } // Resize if($width != $size[0]) { $output_image = imagescale($original_image, $width, -1, IMG_BICUBIC); imagedestroy($original_image); } else { $output_image = $original_image; } // Rotate if($rotate_angle) { $output_image = imagerotate($output_image, $rotate_angle, 0); } // Flip if($is_flipped) { $output_image = imageflip($output_image, IMG_FLIP_HORIZONTAL); } return $output_image; } }