I am trying to take this image, which I converted to a .png file and then want to remove the white background to make it transparent.
I have tried running the following but haven't had any luck.
$strInputFile = 'car.png';
$execScript = '/usr/local/bin/convert '.$strInputFile.' ';
$execScript .= "-transparent white car-new.png";
$output = shell_exec($execScript);
Am I doing something wrong? The new file gets created, but still has the white background.
Did you mean to use
-transparency
rather than-transparent
?Try the following code:
Similar problem with php imagick:
When converting SVG to transparent PNG, dont forget to put this BEFORE $imagick->readImageBlob():
The background of your image is not
white
(I mean 0xFFFFFF), it's 0xFEFEFE. Try:If you're not making a Shell script, then try this:
This should work in a generic terminal. If it doesn't, let me know. Hope it helps!
As the image is a JPEG, which is subject to losses and slight colour inaccuracies, the whites in your image are not actually 100% pure white. ImageMagick has a way of dealing with this through the
-fuzz
setting which allows a degree of fuzziness, or a range of allowable error, when specifying colours.The correct incantation here is: