How can I join a head image and body image so that the head image is precisely fixed over the neck in body image.
Files are at:
- Head Image: http://yajurinfotech.com/projects/stickers/head1.gif
- Body Image: http://yajurinfotech.com/projects/stickers/body2.gif
I have made an attempt at http://yajurinfotech.com/projects/stickers/preview.php.
What I've got at present is:
$h = 'head1.gif';
$b = 'body2.gif';
$headResource = imagecreatefromgif($h);
$bodyResource = imagecreatefromgif($b);
list($headWidth, $headHeight) = getimagesize($h);
list($bodyWidth, $bodyHeight) = getimagesize($b);
$previewHeight = $headHeight+$bodyHeight;
$previewWidth = $headWidth;
$previewResource = imagecreatetruecolor($previewWidth, $previewHeight);
//make background white
$white = imagecolorallocate($previewResource, 255, 255, 255);
imagefill($previewResource, 0, 0, $white);
// Copy head image
imagecopyresized($previewResource,$headResource, ($headHeight/4)+3,($headHeight/2)-3,0,0,$previewWidth/4,$previewHeight/4,$headWidth,$headHeight);
//copy body image
imagecopy($previewResource,$bodyResource,0,$headHeight,0,0,$bodyWidth,$bodyHeight);
header('Content-type: image/gif');
imagegif($previewResource);
As you can see in preview.php
, head image is not placed correctly over the body image.
Can anyone help me find an algorithm that works for both body2.gif
and body1.gif
?