THESE CODES ARE PROVIDED FOR AN EXAMPLE OF HOW TO USE IMAGEMAGICK WITH PHP. CARE SHOULD BE TAKEN WHEN ACCEPTING USER INPUT.
I TAKE NO RESPONSABILTY FOR ANY PROBLEMS THAT MAY OCCURE WHEN USING ANY OF THIS CODE.
IT IS UP TO YOU TO SECURE THE CODE AND VALIDATE USER INPUT.
Resize image to have specified area in pixels. Aspect ratio is preserved.
$cmd = "$input -resize 10000@ "; exec("convert $cmd area.jpg");
Width and height emphatically given, original aspect ratio ignored.
$cmd = "$input -resize 100x100! "; exec("convert $cmd ignored.jpg");
Change dimensions only if both image dimensions exceed specified dimensions.
$cmd = "$input -resize \"100x100<\" "; exec("convert $cmd both_exceded.jpg");
Change as per widthxheight but only if an image dimension exceeds a specified dimension.
$cmd = "$input -resize \"100x100>\" "; exec("convert $cmd exceded.jpg");
Height and width both scaled by specified percentage.
$cmd = "$input -resize 50% "; exec("convert $cmd equal_percent.jpg");
Maximum values of height and width given, aspect ratio preserved.
$cmd = "$input -resize 100x100"; exec("convert $cmd resize_max.jpg");
Height given, width automagically selected to preserve aspect ratio.
$cmd = "$input -resize x100"; exec("convert $cmd resize_height.jpg");
Minimum values of width and height given, aspect ratio preserved.
$cmd = "$input -resize \"100x100^\" "; exec("convert $cmd resize_min.jpg");
Width given, height automagically selected to preserve aspect ratio.
$cmd = "$input -resize 100"; exec("convert $cmd resize_width.jpg");
Height and width individually scaled by specified percentages. (Only one % symbol needed.)
$cmd = "$input -resize 100x50% "; exec("convert $cmd unequal_percent.jpg");