title: Overlay PNG on JPG using Imagick
body: <p>I have the last few hours tried to get a PNG logo with a transparent background on top of a JPG background. I have tried several ways and with several globals as well, but I do not seem to be able to get the result I want.</p>
  
  <p><strong>"First Attempt":</strong></p>
  
  <pre><code>$overlay = new Imagick('overlay.png');
  $image = new Imagick('background.jpg');
  
  $image-&gt;compositeImage($overlay, Imagick::COMPOSITE_DEFAULT, 10, 10);
  $image-&gt;writeImage('background.jpg'); //replace original background
  
  $overlay-&gt;destroy();
  $image-&gt;destroy();
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/WU2Ng.jpg" alt="enter image description here"></p>
  
  <p>As you can see, the Jaguar logo is all black.</p>
  
  <hr>
  
  <p><strong>"Second Attempt"</strong></p>
  
  <pre><code>$overlay = new Imagick('overlay.png');
  $image = new Imagick('background.jpg');
  
  $image-&gt;setImageColorspace($overlay-&gt;getImageColorspace() ); 
  $image-&gt;compositeImage($overlay, Imagick::COMPOSITE_DEFAULT, 10, 10);
  $image-&gt;writeImage('background.jpg'); //replace original background
  
  $overlay-&gt;destroy();
  $image-&gt;destroy();
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/9eLcs.jpg" alt="enter image description here"></p>
  
  <p>This one the Jaguar logo looks like it should, but the background is all messed up now.</p>
  
  <hr>
  
  <p>I have tried with <a href="http://www.php.net/manual/en/imagick.setimagematte.php" rel="nofollow noreferrer">Imagick::setImageMatte</a> and tried to add the <a href="https://stackoverflow.com/questions/6610739/php-imagick-convert-png-to-jpg#answer-6617001">overlay to a white background</a> (thought I does need to have a transparent background) and still it won't display the image properly. I have tried many other variations of the 2 above snippets but they all seem to make the PNG completely or partial black.</p>
  
  <p>What am I missing or doing wrong? Can anyone give me a nudge in the right direction?
  Please note this needs to be done in PHP.</p>
  
  <p>Thank you very much!</p>