$dst_path = 'dst.jpg';
$src_path = 'src.jpg';
$dst = imagecreatefromstring(file_get_contents($dst_path));
$src = imagecreatefromstring(file_get_contents($src_path));
list($src_w, $src_h) = getimagesize($src_path);
imagecopymerge($dst, $src, 10, 10, 0, 0, $src_w, $src_h, 50);
list($dst_w, $dst_h, $dst_type) = getimagesize($dst_path);
switch ($dst_type) {
case 1:
header('Content-Type: image/gif');
imagegif($dst);
break;
case 2:
header('Content-Type: image/jpeg');
imagejpeg($dst);
break;
case 3:
header('Content-Type: image/png');
imagepng($dst);
break;
default:
break;
}
imagedestroy($dst);
imagedestroy($src);