Php – ImageMagick Transparent PNG Background

imagemagickPHP

I am trying to take this image, enter image description here 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.

Best Answer

Similar problem with php imagick:

When converting SVG to transparent PNG, dont forget to put this BEFORE $imagick->readImageBlob():

$imagick->setBackgroundColor(new ImagickPixel('transparent'));
Related Topic