title: png image copied to another image php
body: <p>I'm trying to add a png image onto another image. The only problem I have is that the png image is creating a transparent background around it instead of having the background of the other image.</p>
  
  <p>Here's the image:</p>
  
  <p><img src="https://i.stack.imgur.com/6Ro5m.png" alt="enter image description here"></p>
  
  <p>Expected result:</p>
  
  <p><img src="https://i.stack.imgur.com/KidoX.png" alt="enter image description here"></p>
  
  <p>This is the code:</p>
  
  <pre><code>&lt;?php
      $img_name = "image_" . date("U") . ".png";
      $whoareyou_src = imagecreatefrompng('who-are-you.png');
  
      create_image($img_name, $whoareyou_src);
      print "&lt;img src=". $img_name ."&gt;";
  
      function  create_image($img_name, $whoareyou_src) {
          $im = @imagecreate(800, 610) or die("Cannot Initialize new GD image stream");
          $background_color = imagecolorallocate($im, 0, 128, 128);  // teal
  
          // imagecopy ( resource $dst_im , resource $src_im , int $dst_x , int $dst_y , int $src_x , int $src_y , int $src_w , int $src_h )
          $success = imagecopy($im, $whoareyou_src, 0, 0, 0, 0, imagesx($whoareyou_src), imagesy($whoareyou_src));
          echo "Image Copy: " . $success . "&lt;br&gt;"; // testing
  
          imagepng($im, $img_name);
  
          imagedestroy($im);
          imagedestroy($whoareyou_src);
      }
  
  ?&gt;
  </code></pre>
  
  <p>I thought of setting the background to transparent might help:</p>
  
  <pre><code>imagecolortransparent($whoareyou_src, imagecolorallocate($whoareyou_src, 0, 0, 0));
  </code></pre>
  
  <p>But this did not change anything.</p>
  
  <p><strong>Update</strong></p>
  
  <p>Tried to use <code>imagecopyresampled</code> and <code>alpha</code> settings but still the same result:</p>
  
  <pre><code>&lt;?php
      $img_name = "image_" . date("U") . ".png";
      $whoareyou_src = imagecreatefrompng('who-are-you.png');
  
      create_image($img_name, $whoareyou_src);
      print "&lt;img src=". $img_name ."&gt;";
  
      function  create_image($img_name, $whoareyou_src) {
          $im = @imagecreate(800, 610) or die("Cannot Initialize new GD image stream");
          imagealphablending($im, false);
          imagesavealpha($im,true);
  
          $background_color = imagecolorallocate($im, 0, 128, 128);  // teal
  
          $success = imagecopyresampled($im, $whoareyou_src, 0, 0, 0, 0, imagesx($whoareyou_src), imagesy($whoareyou_src), imagesx($whoareyou_src), imagesy($whoareyou_src));
          echo "Image Copy: " . $success . "&lt;br&gt;";
  
          imagepng($im, $img_name);
  
          imagedestroy($im);
          imagedestroy($whoareyou_src);
      }
  
  ?&gt;
  </code></pre>