ImageMagick TweakPng and sRGB

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
rseeker
Posts: 6
Joined: 2010-07-31T17:45:27-07:00
Authentication code: 8675308

ImageMagick TweakPng and sRGB

Post by rseeker »

I'm looking for a way to process PNG images to:
- report which have embedded profiles
- for those without embedded profile, insert an sRGB chunk

I've been doing this with TweakPng and getting good results, but you have to do it by-hand for each file, and that won't scale.
Can I do this with mogrify/convert?

On the reporting side, using identify -verbose, is there a way to tell from the output whether the sRGB chunk is present?

Here's a diff of identify's output, and I don't see anything. (On the left is for an image without the sRGB chunk, on the right is the same image after inserting an sRGB chunk with TweakPng.)

55,61c55,61
< Rendering intent: Undefined
< Gamma: 0.45454
< Chromaticity:
< red primary: (0.63999,0.33001)
< green primary: (0.3,0.6)
< blue primary: (0.15,0.05999)
< white point: (0.31269,0.32899)
---
> Rendering intent: Saturation
> Gamma: 0.45454
> Chromaticity:
> red primary: (0.64,0.33)
> green primary: (0.3,0.6)
> blue primary: (0.15,0.06)
> white point: (0.3127,0.329)
75c75
< date:modify: 2007-06-07T08:38:28-05:00
---
> date:modify: 2010-08-01T20:54:53-05:00
82,84c82,84
< Pixels per second: 5.707M
< User time: 0.016u
< Elapsed time: 0:01.013
---
> Pixels per second: 15.98M
> User time: 0.000u
> Elapsed time: 0:01.005


Also, in general, what's the difference between ImageMagick's concept of a profile and TweakPng's sRGB chunk? I don't know a lot about this, but after reading for a couple hours they seem like two related but different things.

Thanks.
rseeker
Posts: 6
Joined: 2010-07-31T17:45:27-07:00
Authentication code: 8675308

Re: ImageMagick TweakPng and sRGB

Post by rseeker »

User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: ImageMagick TweakPng and sRGB

Post by fmw42 »

I am not an expert on PNGs, but you could:

See http://www.imagemagick.org/Usage/formats/#png_write. It has a parameter to write PNG chunks, or so it appears.

Also see http://www.imagemagick.org/Usage/formats/#png_non-im for other tools such as pngtrans to find out if you have an sRGB chuck.
rseeker
Posts: 6
Joined: 2010-07-31T17:45:27-07:00
Authentication code: 8675308

Re: ImageMagick TweakPng and sRGB

Post by rseeker »

Thanks for the tips, those are good.

OK, so it looks like 'mogrify -intent AnyValidIntent somefile' has the effect of both creating an sRGB chunk and giving it the specified rendering intent.

Amd if 'identify -verbose' reports any value other than 'unknown' for rendering intent, then you have an sRGB chunk.

Does this make sense, for those who know how this works?

----

Next question: why, if I use 'mogrify -intent AnyValidIntent somefile', does the file go from:

IHDR
pHYs
gAMA
cHRM
IDAT
IEND

to this:

IHDR
gAMA
sRGB
cHRM
bKGD
pHYs
vpAg
IDAT
IDAT
IDAT
IDAT
tEXt
tEXt
IEND

? Are the other changes benign? Or are they necessary, and I'm doing it wrong by just inserting a single sRGB chunk?
rseeker
Posts: 6
Joined: 2010-07-31T17:45:27-07:00
Authentication code: 8675308

Re: ImageMagick TweakPng and sRGB

Post by rseeker »

Actually, now that I compare the results of TweakPNG output with 'identify -verbose' output, I see that reported rendering intent is different. For example, TweakPNG is reporting 'Perceptual' after I assign 'Saturation' with mogrify, and 'identify -verbose' reports 'Saturation'. Since ImageMagick is actively maintained, I'd guess the problem is not there. Can anyone say what to make of this?
Drarakel
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Re: ImageMagick TweakPng and sRGB

Post by Drarakel »

For some details about the sRGB chunk (and other chunks):
http://www.libpng.org/pub/png/spec/1.2/ ... tml#C.sRGB
rseeker wrote:Next question: why, if I use 'mogrify -intent AnyValidIntent somefile', does the file go from:
...
As the documentation says it: "IM is a general raster image processor, for modifying images."
When you're changing metadata or PNG ancillary chunks, ImageMagick has to be recompress the image itself, too. So, the structure of the file will be a bit different.
As alternative, you could try one of the "Non-ImageMagick PNG" tools (see fmw42's link). For example, pngcrush lets you specify these chunks. (Of course, here, the other data gets modified/recompressed, too - as this is the main purpose of these tools.)
rseeker wrote:Actually, now that I compare the results of TweakPNG output with 'identify -verbose' output, I see that reported rendering intent is different.
That's a bug in ImageMagick. You might report that in the bugs forum here.
rseeker
Posts: 6
Joined: 2010-07-31T17:45:27-07:00
Authentication code: 8675308

Re: ImageMagick TweakPng and sRGB

Post by rseeker »

Post Reply