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 the image and add a 1 pixel border to it
$cmd = " $input14 -resize 250x250 -bordercolor coral4 -border 1x1 ";
exec("convert $cmd temp.png");
// Place the tempory image into the center of a 300x300px background
$cmd = " -size 300x250 xc:black -bordercolor coral4 -border 1x1 temp.png ".
" -gravity center -composite ";
exec("convert $cmd border.jpg");
// Delete the tempory image
unlink("temp.png");
/*
A shorter method and no tempory images.
This uses the imagemagick miff:- which saves the image into the memory.
This uses the image created in the first part of the code in the second part of the code.
The image is resized first and one border added then the background with the next border is created.
+swap is then used to reverse the order of the images or you would be left with a black image
with a border.
*/
$cmd = " ( $input14 -resize 250x250 -bordercolor coral4 -border 1x1 ) ".
" -size 300x250 xc:black -bordercolor coral4 -border 1x1 -gravity center ".
" +swap -composite ";
exec("convert $cmd border.jpg");