Resizing a converted PDF doesn't work

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
johnrellis
Posts: 4
Joined: 2017-07-12T16:05:10-07:00
Authentication code: 1151

Resizing a converted PDF doesn't work

Post by johnrellis »

Resizing of PDFs created by Powerpoint 2016 works, while resizing PDFs created by Word 2016 doesn't. Is this a bug or am I missing something?

Details: The following work:

Code: Select all

magick Word.pdf Word.jpg
magick Powerpoint.pdf Powerpoint.jpg
magick Powerpoint.pdf -resize 512x512 Powerpoint.512.jpg
But this generates an all-black image:

Code: Select all

magick Word.pdf -resize 512x512 Word.512.jpg
The input and output files are here: https://www.dropbox.com/sh/l0ata6szokkh ... bjea?dl=0

Version: ImageMagick 7.0.6-0 Q16 x64 2017-06-11
Windows 10
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Resizing a converted PDF doesn't work

Post by snibgo »

If you examine word.pdf in Adobe Reader, you will see it has opaque black letters on a transparent background. JPEG can't record transparency, so you get black letters on a black background.

The cure is to flatter over whatever colour you want for the background, eg:

Code: Select all

magick word.pdf -background Yellow -layers Flatten w.png
snibgo's IM pages: im.snibgo.com
johnrellis
Posts: 4
Joined: 2017-07-12T16:05:10-07:00
Authentication code: 1151

Re: Resizing a converted PDF doesn't work

Post by johnrellis »

Thanks much for your reply.

Why doesn't the background get turned black when there is no resizing?

Code: Select all

magick Word.pdf Word.jpg
Word.jpg has a white background.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Resizing a converted PDF doesn't work

Post by snibgo »

The converted word.pdf has fully-transparent white pixels.

Transparent pixels have colours. A pixel may be fully-transparent white, fully-transparent-yellow, or whatever. Saving as JPEG ignores transparency, so each pixel becomes opaque, whatever colour it is "beneath" the transparency.

Many IM operations such as "-resize" treat transparency carefully so the colour "beneath" the transparency doesn't get mixed with the opaque or semi-transparent pixels. But one side effect is that all fully-transparent pixels of any colour become fully-transparent black.
snibgo's IM pages: im.snibgo.com
johnrellis
Posts: 4
Joined: 2017-07-12T16:05:10-07:00
Authentication code: 1151

Re: Resizing a converted PDF doesn't work

Post by johnrellis »

Thanks for the hint. I found this explanation of why -resize doesn't preserve the color of transparent pixels: viewtopic.php?f=22&t=22287 . I couldn't find anything in the documentation about this, though.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Resizing a converted PDF doesn't work

Post by snibgo »

Yes. See also the SVG Compositing Specification.

When two or more pixels are combined, because of composite or resize or whatever, the resulting pixel colour values usually come from the colour values of each pixel multiplied by its alpha. (The resulting alpha comes from the alphas only, not the colours, of the individual pixels.)

When an input alpha is zero, multiplying this by any colour gives zero. Hence output pixels have colour values of zero, black.

Mathematically, it makes sense.
snibgo's IM pages: im.snibgo.com
johnrellis
Posts: 4
Joined: 2017-07-12T16:05:10-07:00
Authentication code: 1151

Re: Resizing a converted PDF doesn't work

Post by johnrellis »

Thanks again.
Post Reply