title: PHP Transparent Image Layering Problems
body: <p>I just can't tell why this:</p>
  
  <pre><code>&lt;?php
  
       $image = imagecreatefromjpeg($_GET['u']);
       imagealphablending($image, true);
       imagesavealpha($image,true);
       $overlay = imagecreatefrompng("overlay.png");
       imagealphablending($overlay, true);
       imagesavealpha($overlay,true);
       $finalImage = imagecreate(85,85);
       imagealphablending($finalImage, true);
       imagesavealpha($finalImage,true);
  
       $trans = imagecolorallocate($finalImage,255,0,0);
       imagecolortransparent($finalImage,$trans);
       imagefill($finalImage, 0, 0, $trans);
  
       imagecopy($finalImage, $image, 5, 5, 0, 0, 75, 75);
       imagecopy($finalImage, $overlay, 0, 0, 0, 0, 85, 85);
       imageDestroy($image);
       imageDestroy($overlay);
  
  
       // Content type
       header('Content-type: image/png');
       imagepng($finalImage);
       imagedestroy($finalImage);
  </code></pre>
  
  <p>?></p>
  
  <p>Produces this:</p>
  
  <p><a href="http://alanjack.co.uk/travel/0rotatedImage.php%20(1).png" rel="nofollow noreferrer">alt text http://alanjack.co.uk/travel/0rotatedImage.php%20(1).png</a></p>
  
  <p>When doing imagecopy one or the other produces healthy results:</p>
  
  <pre><code>         imagecopy($finalImage, $image, 5, 5, 0, 0, 75, 75);
       //imagecopy($finalImage, $overlay, 0, 0, 0, 0, 85, 85);
       //ImageDestroy($image);
       //ImageDestroy($overlay);
  </code></pre>
  
  <p>giving:</p>
  
  <p><a href="http://alanjack.co.uk/travel/1rotatedImage.php%20(1).png" rel="nofollow noreferrer">alt text http://alanjack.co.uk/travel/1rotatedImage.php%20(1).png</a></p>
  
  <p>and </p>
  
  <pre><code>         //imagecopy($finalImage, $image, 5, 5, 0, 0, 75, 75);
       imagecopy($finalImage, $overlay, 0, 0, 0, 0, 85, 85);
       //ImageDestroy($image);
       //ImageDestroy($overlay);
  </code></pre>
  
  <p>giving:</p>
  
  <p><a href="http://alanjack.co.uk/travel/2rotatedImage.php%20(1).png" rel="nofollow noreferrer">alt text http://alanjack.co.uk/travel/2rotatedImage.php%20(1).png</a></p>
  
  <p>Could it be some kind of palette inconsistency or something - something to do with one being a PNG and another a JPEG?</p>
  
  <p>Grrrrrrrr ... Alan angry ... ALAN WANT SMASH!!!</p>