I want to remove the white background of any image uploaded on the site working on PHP platform. The uploading function is done but messed up with this functionality.
Here is the link I found here: Remove white background from an image and make it transparent
But this is doing reverse. I want to remove the colored background and make it image with transparent background.
On the opened Save for Web box, from the right section, click to select PNG-24 option from the Settings drop-down list. Check the Transparency checkbox. Finally click the Save button to save the image with the transparent background.
Select the > Save As option. From the Format options, choose either TIFF, PNG, or GIF. If you've picked the GIF or TIFF format, make sure to check the > Save Transparency box on the bottom left.
Transparency is not done in HTML, but is a part of the image itself. The browser will see the image as a PNG and display it as a PNG automatically. To add transparency to the image, you will have to edit the file with a graphics editor like Photoshop. Save this answer.
Since you only need single-color transparency, the easiest way is to define white with imagecolortransparent()
. Something like this (untested code):
$img = imagecreatefromstring($your_image); //or whatever loading function you need
$white = imagecolorallocate($img, 255, 255, 255);
imagecolortransparent($img, $white);
imagepng($img, $output_file_name);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With