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.
// Get the image size to creat the mask
// This can be done within Imagemagick but as we are using php this is simple.
$size = getimagesize("$input14");
// Create a mask with a round hole
$cmd = " -size {$size[0]}x{$size[1]} xc:none -fill black ".
" -draw \"circle 120,220 120,140\" ";
exec("convert $cmd mask.png");
// Cut out the hole in the top image
$cmd = " -compose Dst_Out mask.png -gravity south $input14 -matte ";
exec("composite $cmd result_dst_out1.png");
// Composite the top image over the bottom image
$cmd = " $input20 result_dst_out1.png -geometry +60-20 -composite ";
exec("convert $cmd output_temp.jpg");
// Crop excess from the image where the bottom image is larger than the top
$cmd = " output_temp.jpg -crop 400x280+60+0 ";
exec("convert $cmd composite_sunflower_hard.jpg ");
// Delete tempory images
unlink("mask.png");
unlink("result_dst_out1.png");
unlink("output_temp.jpg");