title: Transparent Circle Cropped Image with PHP
body: <p>I want to crop a circle image using PHP but it seems that my new image have some transparent pixels. Of course, I want ONLY the outside area of the ellipse to have background transparent </p>
  
  <p>My code is listed below:</p>
  
  <pre><code>        $image = imagecreatetruecolor($this-&gt;dst_w, $this-&gt;dst_h);
          imagealphablending($image,true);
          imagecopy ( $image , $image_s , 0, 0, $this-&gt;src_x, $this-&gt;src_y, $this-&gt;dst_w, $this-&gt;dst_h );
          $mask = imagecreatetruecolor($this-&gt;src_x, $this-&gt;src_y);
          $mask = imagecreatetruecolor($this-&gt;dst_w, $this-&gt;dst_h);
          $transparent = imagecolorallocate($mask, 255, 0, 0);
          imagecolortransparent($mask, $transparent);
          imagefilledellipse($mask, $this-&gt;dst_w/2, $this-&gt;dst_h/2, $this-&gt;dst_w, $this-&gt;dst_h, $transparent);
          $red = imagecolorallocate($mask, 0, 0, 0);
          imagecopymerge($image, $mask, 0, 0, 0, 0, $this-&gt;dst_w, $this-&gt;dst_h,100);
          imagecolortransparent($image, $red);
          imagefill($image,0,0, $red);
  
          if ($ext=="jpg" || $ext=="jpeg") {
              imagejpeg($image, $this-&gt;croppedImage);
          } else if ($ext=="png") {
              imagepng($image, $this-&gt;croppedImage);
          }           
          imagedestroy($image);
          imagedestroy($mask);
          // &lt;------- END generate cropped Image -------&gt;
  
          // &lt;------- START generate transparent Image -------&gt;               
          $this-&gt;generateTransparentImage('circle');
  </code></pre>
  
  <p>......</p>
  
  <p>An example of actual generated image is here:
  <img src="https://i.stack.imgur.com/9MO2C.png" alt="enter image description here"></p>
  
  <p>EDIT: generateTransparentImage function has nothing to do with the code listed above; this function generate this image: 
  <a href="http://s7.postimage.org/byybq9163/Koala7_500x375_c_transparent.png" rel="nofollow noreferrer">http://s7.postimage.org/byybq9163/Koala7_500x375_c_transparent.png</a></p>