title: Join multiple PNG Images into a single one PNG using PHP
body: <p>I´m trying to make custom sprites based on my own PNGs using PHP, but I got two problems:</p>
  
  <blockquote>
    <ol>
    <li>Output Image it´s a collection of stacked PNGs... in other words: source PNGs are one over other.</li>
    <li>I need a transparent background for the output image!</li>
    </ol>
  </blockquote>
  
  <p>This is the code that I used:</p>
  
  <pre><code>$width = 210;
  $height = 190;
  
  $layers = array();
  $layers[] = imagecreatefrompng("copy.png");
  $layers[] = imagecreatefrompng("cut.png");
  
  $image = imagecreatetruecolor($width, $height);
  
  // to make background transparent?
  imagealphablending($image, false);
  $transparency = imagecolorallocatealpha($image, 0, 0, 0, 127);
  imagefill($image, 0, 0, $transparency);
  imagesavealpha($image, true);
  
  imagealphablending($image, true);
  for ($i = 0; $i &lt; count($layers); $i++) {
      imagecopy($image, $layers[$i], 0, 0, 0, 0, $width, $height);
  }
  imagealphablending($image, false);
  imagesavealpha($image, true);
  
  imagepng($image, 'final_img.png'); 
  </code></pre>