S
S
synapse_people2017-10-18 10:23:19
PHP
synapse_people, 2017-10-18 10:23:19

How to make white background transparent?

Hello everyone)
Tell me, pliz, how can I cut out a white background from an image (more precisely, replace it with transparency) using the Imagick PHP extension so that it does not eat away pieces from a normal image? That is, replace all white pixels with transparency, and along the edge so that there is antialiasing (smooth transition from transparent to opaque).
Interested in the method, in the direction of which it is worth looking .. working code is also suitable))
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
synapse_people, 2017-10-18
@synapse_people

Who will need:

$fuzz = 0.1;

        $im = new Imagick();

        $im->readimage('файл.jpg');
        $im->setImageFormat('png');

        $max = $im->getQuantumRange();
        $max = $max["quantumRangeLong"];

        $im->trimImage($fuzz * $max);
        $im->transparentPaintImage($im->getImagePixelColor(0, 0), 0, $fuzz * $max, FALSE);

        header('Content-Type: image/png');
        echo $im->getImageBlob();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question