How to merge two image using PHP

Merge two image using PHP – Merging image using php is quit easy thanks to PHP GD Library a very powerful image alteration library written for PHP there is one predefined PHP function which you can use to merging the images quickly.The function is imagecopymerge — Copy and merge part of an image

You can use following function and pass image1 and image2 and get the final merge image as output.

function mergeImg($img1, $img2) {
// Create image instances
$dest = imagecreatefromgif($img1);
$src = imagecreatefromgif($img2);
// Copy and merge
imagecopymerge($dest, $src, 10, 10, 0, 0, 100, 47, 75);
// Output and free from memory
header('Content-Type: image/gif');

Call the function and pass the both images which need to merge.

mergeImg("1.gif", "2.gif");

Posted in: PHP