Answer the question
In order to leave comments, you need to log in
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
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 questionAsk a Question
731 491 924 answers to any question