Page 1 of 1

Preserving Colourspace when resizing

Posted: 2012-07-20T06:14:42-07:00
by zyndor
Hi all,

The premise is that I'm trying to batch resize a bunch of 32bit png-s with transparency. The 3rd party tool that I'm using to load the result images complains for some of them that it doesn't support non-8-bit Greyscale.

Quite clearly, neither the original, nor the resulting images are greyscale. The command I'm using is:

Code: Select all

mogrify -resize 50x50% -depth 8 *.png
The result that identify yields is this (excerpt):
calendar_day_future_dark.png PNG 119x107 119x107+0+0 8-bit DirectClass 352B 0.000u 0:00.000 (sRGB / PaletteAlpha / 8-bit)
calendar_day_future_light.png[1] PNG 119x107 119x107+0+0 8-bit DirectClass 352B 0.000u 0:00.000 (sRGB / PaletteAlpha / 8-bit)
calendar_day_past_dark.png[2] PNG 119x107 119x107+0+0 8-bit PseudoClass 2c 339B 0.000u 0:00.000 (sRGB / Palette / 8-bit)
calendar_day_past_light.png[3] PNG 119x107 119x107+0+0 8-bit PseudoClass 2c 339B 0.000u 0:00.000 (sRGB / Palette / 8/4-bit)
calendar_day_present.png[4] PNG 119x107 119x107+0+0 8-bit PseudoClass 2c 327B 0.000u 0:00.000 (Gray / Bilevel / 8/1-bit)
Now, the problem is that out of these five images the first four load fine, and it is the last one that fails (the originals all load fine). "calendar_day_present.png" is actually a solid white rectangle. (Windows 7 Explorer's Bit Depth column reports a bit depth of 1 on all of these files; the originals had 32 - I'm not sure how accurate this feature is, but most of my 24/32 bit originals went to 1/4/8 bits according to it.)

How can I make sure that each image has the same Colourspace as its original when using mogrify, i.e. they're not converted into greyscale / palettised images and the alpha channel isn't lost?

Thank you for your help in advance.

Re: Retaining colour mode while resizing

Posted: 2012-07-20T06:41:59-07:00
by glennrp
Use the PNG32 subformat to force all PNGs to be written as 8-bit-per-sample RGBA

e.g.,

Code: Select all

mogrify -define png:format=PNG32 files

Re: Preserving Colourspace when resizing

Posted: 2012-07-20T06:44:01-07:00
by zyndor
And when I've made it as far as spotting that it's a colorspace issue...;)

http://www.imagemagick.org/www/command- ... colorspace

Re: Preserving Colourspace when resizing

Posted: 2012-07-20T06:44:31-07:00
by zyndor
@glennrp: thank you, I'll try that!

Re: Preserving Colourspace when resizing

Posted: 2012-07-20T06:46:43-07:00
by glennrp
I revised my response to demonstrate "mogrify" instead of "convert", see above.

Re: Preserving Colourspace when resizing

Posted: 2012-07-20T06:53:34-07:00
by glennrp
You could also try

Code: Select all

-define png:bit-depth=8
or

Code: Select all

-define png:color-type=3
if it's only the bit depth or colortype that is problematic. That will probably
result in much smaller files than forcing png32 RGBA output.

Re: Preserving Colourspace when resizing

Posted: 2012-07-20T06:54:38-07:00
by zyndor
@glennrp: thank you so much for your help -- that did the trick (the -colorspace switch still doesn't seem to work).