-write .png = unexpected

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
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

-write .png = unexpected

Post by GreenKoopa »

Inserting a "-write b.png" into my command alters the working colorspace for subsequent operations. Is this a bug? Writing out to a .tif doesn't do this, so that's my work-around. A contrived but simple example:

Code: Select all

ImageMagick 6.6.6-5 2010-12-12 Q16

> convert -size 10x300 gradient:red-blue -colorspace Lab -write miff:a -write b.png -write miff:c null:

> convert a -format "%r %[colorspace]" info:
DirectClassLab Lab

> convert b.png -format "%r %[colorspace]" info:
DirectClassRGB RGB

> convert c -format "%r %[colorspace]" info:
DirectClassRGB RGB
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: -write .png = unexpected

Post by anthony »

MIFF can handle a LAB colorspace. PNG is limited to purely RGB colorspace!!!!!

You can force it to save LAB values in a PG image by setiing -set colorspace RGB
BUt PNG will not know (and can't record) that the values stored are actually in LAB colorspace.
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: -write .png = unexpected

Post by anthony »

Any particular reason you want to save in LAB colorspace?
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: -write .png = unexpected

Post by GreenKoopa »

+write helped here.
anthony wrote:Any particular reason you want to save in LAB colorspace?
I was trying out a lightness adjustment. It worked well for one, HSB looked better for the other. -distort SRT made a mess of edges in Lab. Going from RGB to Lab gave slightly different results than Photoshop, but -set colorspace sRGB generated results way different. I was troubleshooting inserting -write everywhere. I never did corner it, but something seemed off. Between this and curves, and hurried for the holidays, I gave up and Photoshopped the six images. I hoped to help out with another bug, but I'm feeling more frustrated and tired than helpful today. :(
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: -write .png = unexpected

Post by glennrp »

GreenKoopa wrote:Inserting a "-write b.png" into my command alters the working colorspace for subsequent operations.
In 6.6.6-7 beta, the PNG encoder makes a clone of the image before modifying it. The original image is left intact for further operations.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: -write .png = unexpected

Post by magick »

Use +write rather than -write. The +write option ensures there are no image side effects in your work flow.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: -write .png = unexpected

Post by anthony »

Magick, what sort of side effects? Colorspace change? Color Quantization and Dither?
Anything else?
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: -write .png = unexpected

Post by magick »

The side effects depends on the image format. Gif for example color reduces any image with more than 256 unique colors.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: -write .png = unexpected

Post by anthony »

I sort of figured, but I just wanted it to be clear.

I'll include that note in IM Examples, File Handling, Saving Images.
http://www.imagemagick.org/Usage/files/#write
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply