I can't seem to merge 2 images for some reason and I have no clue what I'm doing wrong. This is still a bit new to me. here is the code I have:
$source = 'http://localhost:8888/develop/trunk/develop/wp-content/uploads/2012/07/card01-80x80.jpg';
$im = imagecreatetruecolor(200, 200);
$black = imagecolorallocate($im, 0, 0, 0);
// Make the background transparent
imagecolortransparent($im, $black);
$text_color = imagecolorallocate($im, 255, 255, 255);
imagestring($im, 1, 5, 5, "A Simple Text String", $text_color);
imagejpeg($im, WP_UPLOADS_PATH . 'post-image-generator/1.jpg');
//merge images
$thumb = imagecreatefromjpeg($source);
$destination = imagecreatefromjpeg(WP_UPLOADS_PATH . 'post-image-generator/1.jpg');
imagecopymerge($destination, $thumb, 0, 0, 0, 0, 0, 0, 100);
imagejpeg($destination, WP_UPLOADS_PATH . 'post-image-generator/1.jpg');
echo "
<style></style>
<img src='" . WP_UPLOADS_URL . 'post-image-generator/1.jpg' . "' />
";
imagedestroy($thumb);
imagedestroy($destination);
imagedestroy($im);
It generates the following:
but should also include the following image:
Any help is appreciated
As far as I can tell without actually testing it, it's this:
imagecopymerge($destination, $thumb, 0, 0, 0, 0, 0, 0, 100);
The area you're copying from starts at 0,0 in $thumb, and the width and height of the area to be copied is 0 and 0. Since the source picture is 80x80 and you want the whole thing to be copied to the top left corner of the first image, you'd need to change it to:
imagecopymerge($destination, $thumb, 0, 0, 0, 0, 80, 80, 100);
This copies the whole 80-pixel image to the top left corner of $destination.