convert pdf to transparent png
I'm using ImageMagick to convert a pdf file to a png (thumbn开发者_StackOverflow社区ail) image, and it works well. I'm wondering whether it's possible to convert the pdf, which has a white background, to a png file with a transparent background (i.e. set all the white pixels to transparent).
This is the PHP code i'm currently using (which results in a png file with a white background):
/* Open first page of PDF file */
$im = new imagick($pdf_filepath . '[0]');
/* Scale */
$im->thumbnailImage($width, $height);
/* Convert to png */
$im->setImageFormat('png');
/* Save file */
$result = $im->writeImage($thumbnail_filepath);
Check out: http://imagemagick.org/Usage/channels/#mask_creation
I think you will have to create it to GIF first and then back to png if you wish.
精彩评论