简体   繁体   中英

convert pdf to transparent png

I'm using ImageMagick to convert a pdf file to a png (thumbnail) 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 (ie 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM