title: PHP - Watermark PNG Transparency/Alpha
body: <p>I know this has been covered PLENTY of times but I keep trying different scripts and modifying the one I have, and I <em>still</em> can't get my PNG-24 watermark.png to be transparent over the top of my parent image.</p>
  
  <p>This is what I have currently:</p>
  
  <pre><code>&lt;?
  
  header('content-type: image/jpeg');
  
  $watermark = imagecreatefrompng('watermark.png');
  $watermark_width = imagesx($watermark);
  $watermark_height = imagesy($watermark);
  
  $image = imagecreatefromjpeg($imageURL);
  $image = imagecreatetruecolor($watermark_width, $watermark_height);
  $size = getimagesize($imageURL);
  
  imagealphablending($image, false);
  imagesavealpha($image, true);
  
  $dest_x = $size[0] - $watermark_width - 5;
  $dest_y = $size[1] - $watermark_height - 5;
  
  imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100);
  
  imagejpeg($image);
  
  imagedestroy($image);
  imagedestroy($watermark);
  
  ?&gt;
  </code></pre>
  
  <p>I've just read another SO question and one of the answers advised that it won't be transparent if you don't add these two lines:</p>
  
  <pre><code>imagealphablending($image, false);
  imagesavealpha($image, true);
  </code></pre>
  
  <p>I added them and still not. I tried setting headers and output to PNG instead but still no luck. I loaded the watermark in my browser (raw) and it's definitely transparent but just not on the image. Surely this can't be that difficult? Any ideas what I'm doing wrong?</p>