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,000 points
1,140 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 ...READ MORE

May 27, 2022 in PHP by Kichu
• 19,040 points
3,159 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,840 points
1,273 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,840 points
4,787 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,840 points
35,051 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,840 points
4,294 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,840 points
4,839 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,040 points
1,444 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,600 points
408 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,000 points
6,209 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,561 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