Skip to content

Instantly share code, notes, and snippets.

@ma4a
Created May 18, 2013 21:00
Show Gist options
  • Select an option

  • Save ma4a/5605779 to your computer and use it in GitHub Desktop.

Select an option

Save ma4a/5605779 to your computer and use it in GitHub Desktop.
Merge 2 PNG-Files without losing alpha channel transparency information
<?php
function mergePNGs($dst_fileURL, $temp_fileURL)
{
$resolutionX = 1000;
$resolutionY = 1000;
$dst_im = imagecreatefrompng($dst_fileURL) or die('Error reading image file');
$src_im = imagecreatefrompng($temp_fileURL) or die('Error reading image file');
imagealphablending($dst_im, true);
imagesavealpha($dst_im, true);
imagealphablending($src_im, true);
imagesavealpha($src_im, true);
imagecopy($dst_im, $src_im, 0, 0, 0, 0, $resolutionX, $resolutionY);
header("Content-Type: image/png");
imagePNG($dst_im, $dst_fileURL, 2);
imagedestroy($dst_im);
imagedestroy($src_im);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment