开发者

convert pdf to transparent png

开发者 https://www.devze.com 2023-02-12 10:06 出处:网络
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 backgrou

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消