C
C
ChernovGV2020-03-10 09:40:08
PHP
ChernovGV, 2020-03-10 09:40:08

How to change white background to transparent using PHP (GD)?

Good afternoon!
The task is to put your background under the images on a white background. The new background will be light, so if there are light (!= white) pixels around the image, it's okay.

In general, the plan is:

  1. I create a copy of the image but in png format
  2. I'm looking for white (#EEEEEE - #FFFFFF) pixels on it
  3. I delete them, or change them to transparent
  4. The resulting image is applied as a mask to the background.


But I can't find a solution to the 3rd point. Tell me how to change the white background to transparent using PHP (GD)?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Ninazu, 2020-03-10
@ChernovGV

imagecolorat - get the color of a pixel
imagesetpixel - set the color of a pixel
imagecolorallocatealpha - to create an empty color
imagealphablending - set the blending mode
imagesavealpha - save with transparency

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question