php gd can t remove background after creating a circular image

0 votes

I'm positioning a circular picture with a transparent background using a script on another image. When I upload it, the removed pink background colour reappears, but when I open the circle picture in the browser, the pink background colour is gone. It is visible.

 $img1 = imagecreatefromjpeg("/path/uploads/resized-".$_POST["photo"]);

  $x=imagesx($img1)-$width ;
  $y=imagesy($img1)-$height;
  $img2 = imagecreatetruecolor($x, $y);
  $bg = imagecolorallocate($img2, 255, 200, 255);
  imagefill($img2, 0, 0, $bg);
  $e = imagecolorallocate($img2, 0, 0, 0);
  $r = $x <= $y ? $x : $y;

  imagefilledellipse($img2, ($x/2), ($y/2), $r, $r, $e); 
  imagecolortransparent($img2, $e);
  imagecopymerge($img1, $img2, 0, 0, 0, 0, $x, $y, 100);
  imagecolortransparent($img1, $bg);

  $tempimageround = str_replace('.jpg','','/path/uploads/circle-'.$_POST["photo"]).'.png';

  imagepng($img1,$tempimageround);  
  $new_photo2 = imagecreatefrompng($tempimageround);

imagecopy($jpg_image, $new_photo2, $photoleft, $phototop, 0, 0,$photowidth, $photoheight);
imagedestroy($img2);
imagedestroy($img1);

When placed on top of $jpg image, /path/uploads/circle-photo.png maintains the background colour of 255,200,255 while having a transparent backdrop when viewed in the browser. I'm unsure of what I'm lacking.

Aug 4, 2022 in PHP by Kithuzzz
• 38,010 points
877 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In PHP

0 votes
0 answers

Remove Image background with php and save transparent png

I am working on functionality that removes the ...READ MORE

May 27, 2022 in PHP by Kichu
• 19,050 points
2,759 views
0 votes
1 answer

How can I expire a PHP session after 50 minutes?

Hii @kartik, Use the session_set_cookie_params funciton to set the session. If necessary call this function ...READ MORE

answered May 19, 2020 in PHP by Niroj
• 82,880 points
1,031 views
0 votes
1 answer

How do I convert a PDF document to a preview image in PHP?

Hello @kartik, You need ImageMagick and GhostScript <?php $im = new imagick('file.pdf[0]'); $im->setImageFormat('jpg'); header('Content-Type: image/jpeg'); echo ...READ MORE

answered Aug 14, 2020 in PHP by Niroj
• 82,880 points
4,300 views
0 votes
1 answer

How to resolve the problem of losing a session after a redirect in PHP?

Hello @kartik, Carry out these usual checks: Make sure session_start(); is ...READ MORE

answered Aug 24, 2020 in PHP by Niroj
• 82,880 points
33,094 views
0 votes
1 answer

How to remove a child with a specific attribute, in SimpleXML for PHP?

Hii, Just unset the node: $str = <<<STR <a> ...READ MORE

answered Nov 5, 2020 in PHP by Niroj
• 82,880 points
3,787 views
0 votes
1 answer

How to remove a variable from a PHP session array?

Hello @kartik, Try: if (isset($_POST['remove'])) { ...READ MORE

answered Nov 8, 2020 in PHP by Niroj
• 82,880 points
4,382 views
0 votes
0 answers

PHP Merge 2 Images (Insert Face To An Image)

I have 2 images. one face image ...READ MORE

May 27, 2022 in PHP by Kichu
• 19,050 points
1,107 views
0 votes
0 answers

Editing image colors in PHP - color exchange

I am trying to convert all colors ...READ MORE

Jun 12, 2022 in PHP by narikkadan
• 63,420 points
271 views
0 votes
0 answers

How to install Imagick/imagemagick PHP extension on windows 7

Installing Image Magic in Windows 7: instructions ...READ MORE

Aug 4, 2022 in PHP by Kithuzzz
• 38,010 points
5,411 views
+1 vote
2 answers

Scp Php files into server using gradle

Tru something like this: plugins { id ...READ MORE

answered Oct 11, 2018 in DevOps & Agile by lina
• 8,220 points
1,207 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP