So, i have a lot of tiff files and I want to generate thumbnails of them. This thumbnails must have a transparent background.
All tiffs have: a white background and a path along the object (e.g. a can of a coke) and are saved as CMYK.
So i tried a lot of convert
commands (like these and also php Imagick::clipPath
but nothing worked very well (background still there/corrupt image).
convert a.tif -clip -resize 800x600 a.png
convert a.tif -clip -alpha transparent +clip -channel A -resize 800x600 a.png
also this php code:
<?php
$image = new Imagick('a.tif');
$image->clipPath();
$image->setImageFormat('png');
$image->thumbnailImage(800, 600, true);
$image->writeImage('a.png');
here is an example tif file
Maybe somebody knows how to solve this.
EDIT:
The best result returns this: convert test.tif -clip -alpha transparent 1.png
But it saves the background and not the clipped object. (png)
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);