title: Add transparent watermark into image
body: <p>I need to add transparent watermark (transparency in final image - 80%). I created this function to handle it:</p>
  
  <pre><code>function ImageAddWatermark($im, $stamp, $onLeft, $onTop, $margin){       
          // $stamp = imagecreatformpng(...) -&gt; GD resource?
          // not important part - it calculates position of watermark 
          if($onLeft){
              $orgX = $margin;
          } else {
              $orgX = imagesx($im)-$margin-imagesx($stamp);
          }
  
          if($onTop){
              $orgY = $margin;
          }else {
              $orgY = imagesy($im)-$margin-imagesy($stamp);
          }
  
          imagecopymerge($im, $stamp, $orgX, $orgY, 0, 0, imagesx($stamp), imagesy($stamp), 50);
  
          return $im;
      }
  </code></pre>
  
  <p>Result of function:
  <img src="https://i.stack.imgur.com/ax6LP.jpg" alt="error"></p>
  
  <p>But imagecopymerge returns black background instead of transparent. I even heard some opinions, that imagecopymerge isn't exactly the right thing for creating transparent watermarks... </p>
  
  <p>So the question is: <strong>"How can I add a transparent watermark (using alpha?) in jpeg photo?" How can I get rid of that black backgound?</strong> (In original PNG file is transparent)</p>