Background color error on PDF resize

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
broucaries
Posts: 467
Joined: 2008-12-21T11:51:10-07:00

Background color error on PDF resize

Post by broucaries »

(see http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=642098)

convert -density 300 test.pdf -colorspace RGB -resize 900 test.jpg lead to incorrect background color.

It is a regression.

Not tested with lasted upstream imagemagick but do not see solved in changelog

Bastien
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Background color error on PDF resize

Post by magick »

Not a bug. Recent versions of ImageMagick use the Ghostscript pngalpha device to render PDF. The pngalpha device includes an alpha channel. To get the desired results, flatten the image:
  • convert -density 300 -colorspace RGB test.pdf -flatten -resize 900 test.jpg
broucaries
Posts: 467
Joined: 2008-12-21T11:51:10-07:00

Re: Background color error on PDF resize

Post by broucaries »

Sorry but jpeg has no alpha channel. Why not flatten by default ?

At least warning.

Bastien
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Background color error on PDF resize

Post by magick »

Here, the flatten is required before the image is delivered to the JPEG coder. The resize algorithm considers alpha when resizing the RGB channels. Note, the user can change pngalpha to pnmraw in the delegates.xml configuration file and PDF's will always render without an alpha channel.
broucaries
Posts: 467
Joined: 2008-12-21T11:51:10-07:00

Re: Background color error on PDF resize

Post by broucaries »

I understand but without flatten
pdf to png will be correct thanks to alpha channel whereas convertion from pdf to jpg with resize will be not correct.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Background color error on PDF resize

Post by anthony »

magick wrote:Not a bug. Recent versions of ImageMagick use the Ghostscript pngalpha device to render PDF. The pngalpha device includes an alpha channel. To get the desired results, flatten the image:
  • convert -density 300 -colorspace RGB test.pdf -flatten -resize 900 test.jpg
With more recent versions of IM (v6.7.5 onward), especially if multiple images are involved, use -alpha remove

Code: Select all

   convert -density 300 -colorspace RGB test.pdf -background white -alpha remove -resize 900 test.jpg
(default background color is white so the -background isn't really needed in this case)

See IM Examples, "Removing transparency form images"
http://www.imagemagick.org/Usage/masking/#remove
This also shows why you should remove alpha, BEFORE saving to JPEG...
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Background color error on PDF resize

Post by anthony »

broucaries wrote:I understand but without flatten
pdf to png will be correct thanks to alpha channel whereas conversion from pdf to jpg with resize will be not correct.
It is actually 'correct'. But transparenct colours are undefined. You just need to define what they should be.

However I agree that perhaps JPEG saving should apply a '-alpha remove' automatically as part of its coding sequence (especially now a memory efficient operator is available). I would think this should be a IMv7 coder change (in development), and NOT a IMv6 change. JPG transparency problem has been a well known IMv6 thing for far too long.

Note that this assumes that 'background' is actually set correctly (default is white). Who is to say that it is correct in all situations?
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Background color error on PDF resize

Post by fmw42 »

I do not think it should be automatic, since there is no universal background color. The background color is specific to the user's application and/or desires.
Post Reply