CROP

This tutorial covers croping using PHP with Image Magick from the command line. For more information on PHP variables see Lesson I on making backgrounds.
IM COMMANDFUNCTION
-crop WxH-left-topCrop by pixels, right and bottom cut off
-crop WxH+right+bottomCrop by pixels, left and top cut off
-gravity north
-crop 80x50+0+0
Crop by gravity size in pixels to cut out
-gravity center
-crop 80x50%+0+0
Crop by gravity and percent
ORIGINAL IMAGE 214x156
<?
$IN="cards.jpg";
$CROP="-crop 214x156-107-0";
$OUT="JackCard.jpg";
exec ("/usr/bin/convert $IN $CROP +repage $OUT");
?>
<?
$IN="cards.jpg";
$CROP="-crop 214x156+107-0";
$OUT="QueenCard.jpg";
exec ("/usr/bin/convert $IN $CROP +repage $OUT");
?>
<?
$IN="cards.jpg";
$CROP="-crop 214x156-0-125";
$OUT="TopCard.jpg";
exec ("/usr/bin/convert $IN $CROP +repage $OUT");
?>
<?
$IN="cards.jpg";
$CROP="-crop 214x156-0+125";
$OUT="BottomCard.jpg";
exec ("/usr/bin/convert $IN $CROP +repage $OUT");
?>
<?
$IN="cards.jpg";
$CROP="-crop 214x156-120-125";
$OUT="JackTop.jpg";
exec ("/usr/bin/convert $IN $CROP +repage $OUT");
?>
<?
$IN="cards.jpg";
$CROP="-crop 214x156+120-125";
$OUT="QueenTop.jpg";
exec ("/usr/bin/convert $IN $CROP +repage $OUT");
?>
<?
$IN="cards.jpg";
$GRAVITY="-gravity center";
$CROP="-crop 50x50%+0+0";
$OUT="CenterCard.jpg";
exec ("/usr/bin/convert $IN $GRAVITY $CROP +repage $OUT");
?>
<?
$IN="cards.jpg";
$GRAVITY="-gravity north";
$CROP="-crop 80x50%+0+0";
$OUT="NorthCard.jpg";
exec ("/usr/bin/convert $IN $GRAVITY $CROP +repage $OUT");
?>
<?
$IN="cards.jpg";
$GRAVITY="-gravity north";
$CROP="-crop 80x50+0+0";
$OUT="NorthPixel.jpg";
exec ("/usr/bin/convert $IN $GRAVITY $CROP +repage $OUT");
?>


Below are a zip of a sample crop script plus a crop form. There is also a text version if you prefer that to the zip.

CROP ZIP

CROP TEXT