ImageMagick's mogrify tool darkens PNGs (when only trying to resize)

2

1

I'm trying to use the simple command to resize images and overwrite the originals:

mogrify -resize 80% *

My source images are semi-transparent PNGs that happen to be grayscale. The resize operation works, but is making the images darker.

enter image description here

This used to work on a different machine (Ubuntu 12.04, with ImageMagick 6.6.9-7 2014-03-06) and has broken on a newer machine (Ubuntu 14.04, with ImageMagick 6.7.7-10 2014-03-06). As of this posting, the broken version is the latest version in the Ubuntu 14.04 repos.

Since ImageMagick is a scriptable tool, this is an unfortunate regression that should have been caught by a unit test. I'm off to check my scripted image workflows.

FYI - apparently the convert tool is also affected.

Jeff Ward

Posted 2015-04-07T20:10:14.283

Reputation: 438

2

Try to add -type truecolorAlpha (check here)

– Hastur – 2015-04-07T20:49:59.257

Yes, the -type truecolorAlpha option also appears to workaround the bug. – Jeff Ward – 2015-04-07T21:33:02.793

Answers

1

Adding a -type truecolorAlpha can solve this problem.

It's possible to find an explanation related with the kind of truecolor PNG of the original file and the different palette size before and after the resizing operation.

Essentially it was a bug from a wrong recognition of an iCCP profile from PNG (colortype 6) that was recognised as sRGB, and can occur in similar situation.

Hastur

Posted 2015-04-07T20:10:14.283

Reputation: 15 043

0

I found a blog post showing a workaround by specifying the format of the output. For me, I wanted semi-transparent PNGs, so the best choice was to add the -define png:format=png32 option:

mogrify -define png:format=png32 -resize 80% *

(The blog suggests -define png:format=png24 but that appears to limit output alpha to 1-bit.)

Jeff Ward

Posted 2015-04-07T20:10:14.283

Reputation: 438