Convert tiff (with path) to png and remove background (transparent) - with Imagemagick in PHP Convert tiff (with path) to png and remove background (transparent) - with Imagemagick in PHP shell shell

Convert tiff (with path) to png and remove background (transparent) - with Imagemagick in PHP


Found it after trying it for hours.

convert can.tif -alpha transparent -clip -alpha opaque result.png

So it must be executed with e.g. shell_exec - I didn't found any possible solution to do it with the Imagick-PHP class.

The problem was an old imagemagick version and also the wrong order of command attributes.


The solution with the PHP imagick extension is to replicate the same set of commands:

$imagick->setImageAlphaChannel(\Imagick::ALPHACHANNEL_TRANSPARENT);$imagick->clipImage();$imagick->setImageAlphaChannel(\Imagick::ALPHACHANNEL_OPAQUE);