BORDERS AND FRAMES

This tutorial covers some of the functions available for using PHP with Image Magick from the command line to add frames or borders to images. For more information on PHP variables see Lesson I on making backgrounds. The commands for framing are pretty self explanatory. There are samples of the scripts and effects below.
IM COMMANDFUNCTION
-mattecolor red -frame 25x25+0+25red frame 25x25 in size +0+25 sunken
25x25 +25+0 raised
-bordercolor '#0000ff' -border 10x10blue border 10x10
+raise 25x25raised shadow 25x25
-raise 25x25sunken shadow 25x25
<?
$FRAME="-mattecolor red -frame 25x25+0+25";
$URL="gradJack.jpg";
$OUT="Redframe.gif";
exec ("/usr/bin/convert $FRAME $URL $OUT");
?>
Changed the bevel of above script to +25+0.
$FRAME="-mattecolor red -frame 25x25+25+0";

For this to work, the bevel must be no greater than the size of the frame and one value must be 0.
$FRAME="-mattecolor red -frame 15x15+5+5";
Same script with an equal bevel.
<?
$BC="-bordercolor '#0000ff' -border 10x10";
$URL="gradJack.jpg";
$OUT="Blueborder.gif";
exec ("/usr/bin/convert $BC $URL $OUT");
?>
<?
$RAISE="+raise 25x25";
$URL="gradJack.jpg";
$OUT="Raise.gif";
exec ("/usr/bin/convert $RAISE $URL $OUT");
?>
<?
$SUNK="-raise 25x25";
$URL="gradJack.jpg";
$OUT="Sunk.gif";
exec ("/usr/bin/convert $SUNK $URL $OUT");
?>

<?
$BC="-bordercolor '#0000ff' -border 10x10";
$FRAME="-mattecolor red -frame 25x25+25+0";
$SUNK="-raise 25x25";
$RAISE="+raise 25x25";
$URL="gradJack.jpg";
$OUT="Allframe.gif";
exec ("/usr/bin/convert $SUNK $RAISE $BC $FRAME $BC $URL $OUT");
?>
<?
$BLUE="-bordercolor '#0000ff' -border 8x0";
$GR="-bordercolor '#00ff00' -border 8x0";
$RED="-bordercolor '#ff0000' -border 8x0";
$YEL="-bordercolor '#ffff00' -border 8x0";
$PINK="-bordercolor '#ff00ff' -border 8x0";
$URL="gradJack.jpg";
$OUT="Borders.gif";
exec ("/usr/bin/convert $BLUE $GR $RED $YEL $PINK $URL $OUT");
?>
This script does not preserve transparent background images. A border will fill in the background with the border color and a frame will change the transparency to an off-white color whether you use a gif or a png image. See samples below.
However you can use the compose operator with Copy to compose a border onto a transparent image and retain the transparency.
<?
$IN="angel.gif";
$BC="-bordercolor limegreen -compose Copy";
$BORDER="-border 20";
$OUT="trborder.gif";
exec ("/usr/bin/convert $IN $BC $BORDER $OUT");
?>
<?
$IN="angel.gif";
$COLOR="-mattecolor limegreen -compose Copy";
$FRAME="-frame 20x20+5+5";
$OUT="trborder.gif";
exec ("/usr/bin/convert $IN $COLOR $FRAME $OUT");
?>


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

FRAME ZIP

FRAME TEXT