Preserving Colourspace when resizing

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
zyndor
Posts: 4
Joined: 2012-07-20T04:41:19-07:00
Authentication code: 15

Preserving Colourspace when resizing

Post 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.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Retaining colour mode while resizing

Post 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
Last edited by glennrp on 2012-07-20T06:46:01-07:00, edited 1 time in total.
zyndor
Posts: 4
Joined: 2012-07-20T04:41:19-07:00
Authentication code: 15

Re: Preserving Colourspace when resizing

Post 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
Last edited by zyndor on 2012-07-20T06:45:11-07:00, edited 1 time in total.
zyndor
Posts: 4
Joined: 2012-07-20T04:41:19-07:00
Authentication code: 15

Re: Preserving Colourspace when resizing

Post by zyndor »

@glennrp: thank you, I'll try that!
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Preserving Colourspace when resizing

Post by glennrp »

I revised my response to demonstrate "mogrify" instead of "convert", see above.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Preserving Colourspace when resizing

Post 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.
zyndor
Posts: 4
Joined: 2012-07-20T04:41:19-07:00
Authentication code: 15

Re: Preserving Colourspace when resizing

Post by zyndor »

@glennrp: thank you so much for your help -- that did the trick (the -colorspace switch still doesn't seem to work).
Post Reply