gographics / imagick

Go binding to ImageMagick's MagickWand C API
https://godoc.org/github.com/gographics/imagick/imagick
Other
1.75k stars 182 forks source link

Background is lost in image converted from PDF #291

Closed agarwalanirudh closed 1 year ago

agarwalanirudh commented 1 year ago

Upon converting PDF to JPG, background is completely black, where as in PNG also it turned grey Original PDF: sample.pdf

Outputs:

image
justinfx commented 1 year ago

It's because your pdf has a transparent background. PNG supports transparency so it appears grey. JPG does not support transparency so it sets the background black.

You need to choose a background color and then flatten the images:

The same thing happens with the convert command:

convert sample.pdf bad.png
convert sample.pdf -background '#FFFFFF' -flatten good.png
agarwalanirudh commented 1 year ago

I had tried background property but that didn't do the trick. Although flattening the layers did solve the problem. Thanks @justinfx for quick response :)

agarwalanirudh commented 1 year ago

@justinfx , I realised another issue when using -flatten parameter. It worked fine for this PDF and any other single page PDF, but when I try with multi page PDF, it results in a single image. Where as earlier it used to generate image for each page.

justinfx commented 1 year ago

Well, I know it's not a bug with this binding library. It's a general "how to" ImageMagick question. You might be able to get better help with learning to use ImageMagick via their forum? There aren't going to be a lot of eyes on this issue tracker for this, other than me trying to maintain the library.