This function is intended to serve as an example for the "imageCopyMerge"-"ImageCopyResized", "ImageColorTransparent" functions.
I hope it will help.
This function pick an image, square cut it resampled at the size requested and finishing merge the result with another one to obtain a circular image result. I have a problem to obtain an thumbnail that respect the colors and at the same time where cutted in a circular form, I hope this solution can gives you a clue to obtain a free form images, I use this one also to create multicutted images.
<?php
$generalsrc="$image"; $final_thumbwidth ="125";
$final_thumbheight ="125";
$abc = imagecreatefromjpeg("$generalsrc");
$def = imagecreatetruecolor($final_thumbwidth, $final_thumbheight);
$src_mx = round((imagesx($abc) / 2)-"0.1"); $src_my = round((imagesy($abc) / 2)-"0.1"); $src_x = ($src_mx * 2);
$src_y = ($src_my * 2);
$src_sq = ($src_x >= $src_y)?$src_y:$src_x; $pl = ($src_x >= $src_y)?"1":"2"; $strt_pntx = ($pl=="1")?round(($src_my / 2)-"0. 1"):"0"; $strt_pnty = ($pl=="2")?round(($src_mx / 2)-"0. 1"):"0"; imagecopyresized($def, $abc, 0, 0, $strt_pntx, $strt_pnty, $final_thumbwidth, $final_thumbheight, $src_sq, $src_sq);
$overlay_img = imagecreatefromPNG("circle_125.png"); $src_w = "ImageSX($overlay_img)";
$src_h = "ImageSY($overlay_img)";
$can_img = imagecreatetruecolor($src_w, $src_h);
$black = ImageColorAllocate ($overlay_img, 0, 0, 0);
ImageColorTransparent($overlay_img , $black);
imagecopy($can_img, $def, 0,0,0,0, $src_w, $src_h);
imagecopymerge($can_img, $overlay_img , 0,0,0,0, ImageSX($overlay_img), ImageSY($overlay_img),100); ImageJPEG($can_img,"merge_$generalsrc",100);
imagedestroy($overlay_img);
imagedestroy($can_img);
ImageDestroy($abc);
ImageDestroy($def);
print "<HTML><HEAD><TITLE>test</TITLE></HEAD><BODY>
original:<hr><img src=\"$generalsrc\" width=\"300\"><br><br><br>new:<hr><img src=\"merge_$generalsrc\">
<br>width = $src_x
<br>height = $src_y
<br>mdlw = $src_mx
<br>mdlh = $src_my
<br>sqr = $src_sq
<br>pl = $pl
<br>start point x = $strt_pntx
<br>start point y = $strt_pnty
</BODY></HTML>";
?>