I'm trying to merge two png images using the following code:
$imgl = "myFirstImage.png";
$img2 = "mySecondImage.png";
// Create image instances
$dest = imagecreatefrompng($imgl);
$src = imagecreatefrompng($img2);
imagecolortransparent($src, imagecolorat($src, 0, 0));
// Copy and merge
$src_x = imagesx($src);
$src_y = imagesy($src);
imagecopymerge($dest, $src, 0, 0, 0, 0, $src_x, $src_y, 100);
// Output and free from memory
header('Content-Type: image/png');
imagepng($dest);
imagedestroy($dest);
imagedestroy($src);
However, the output is total junk. It looks something like this:
‰PNG IHDR#5P IDATxœìÝÏ“dÕy7ø›ÕD¨xÛ¶d1~Ýt´»±(Gmýxß DH[-g´°ý‡X+ë‘´ðš&mf4²ˆQlC»aÔ´°©±•]•³H”¤2³²nÞ¼÷žçœóù„ÃÑ¢»«NWeÝsóùÞç9“ù|Þtr”z@Æ$ @w—S/Ho2™œ÷[¬»M”¡
;"„~¹’@µ$ PŽÑr…–\^ ’ÈXïÑ“O=ßí/¾õæ+þW(’¤2sxºÐ9Nèæ¼ÂÅÊ i€’.Œœ+´±™=¸@¾$ W·€!´°ÃZêàŠÙ‘4@8ûyE;¬¦.MIÒ>c(&]ØJä‘4@z†óˆ >I¤Ô2c¨-
Ø´Œ\² I$ èl9¸p@’U›ŒAÀp!-‡¤FraÆ
Ø—¼"4Ààvg†Ã½õæ+.eФ$c“¼’4@ÿJJÅyÑ0>IôlGÌ `ÇjsÃ÷¯Þü›ûï¤]”MÒ½‘1„²È¾õfÓ4ÂŽ¤z cˆéøá+ß¹÷Þâ......[goes on for pages]
I thought it might be a header problem, but that's set as a png in the code. How do I fix this so it renders an image?