aheckmann / gm

GraphicsMagick for node
http://aheckmann.github.com/gm/
6.96k stars 617 forks source link

Problem with color profiles #360

Open axyz opened 9 years ago

axyz commented 9 years ago

Hi, I'm trying to convert an image from adobergb to srgb, for what I've seen the profile instruction only set values on the out array, so I've tried putting the in manually this way:

gm(input).in('-profile').in('path/to/adobergb.icc').stream()

then with that stream I do some resizing and set with .profile it to sRGB this way:

.resize(..)
.other instructions
.profile('/path/to/srgb.icc')
.stream()
.pipe(writeStream);

unfortunately the image exits in sRGB but with pale tones as it ignored the input profile.

If on shell I do gm convert input.jpg -profile /path/to/adobergb.icc -resize 1000x1000 -profile /path/to/srgb.icc output.jpg

it works correctly and the colors are right.

You can see the actual code on https://github.com/axyz/web-resize/blob/master/lib/web-resize.js

I don't know if the problem could also be in the way I pass streams around, but I don't think so because the resizing and multi-step sharpening work as expected, so it looks like it correctly work on all the stages, only the color are incorrect with adobergb images.

Thanks,

axyz commented 9 years ago

UPDATE: if I exec this command from a node shell gm('input.jpg').in('-profile').in('./lib/assets/icc/AdobeRGB1998.icc').resize(null, 900).profile('./lib/assets/icc/sRGB.icc').write('output.jpg', function(err) {console.log(err)})

It seems to work correctly, I'm going to check if it could be a problem with intermediate streams.

axyz commented 9 years ago

gm(gm('scam.jpg').in('-profile').in('./lib/assets/icc/AdobeRGB1998.icc').setFormat('miff').stream()).resize(null, 900).profile('./lib/assets/icc/sRGB.icc').setFormat('jpg').write('ssse.jpg', function(err) {console.log(err)})

this works too...

I've also tried to save using write instead of piping to writeStream, but it is the same. Any clue will be appreciated.

axyz commented 9 years ago

UPDATE: I think I've found the problem: it seems to work correctly without the autoOrient()

Is autoOrient bugged? or do I have to exec it differently?

reco commented 6 years ago

i have the same problem. the moment i am using autoOrient all jpeg images with AdobeRGB loose saturation. as if i would call noProfile()

    obj = gm("./image.jpg")
    obj.resize(2000, 2000, '>')
    obj.quality(90)
    obj.autoOrient()
    obj.write("./image-out.jpg")

@axyz did you find a fix?

fschwahn commented 5 years ago

gm does automatically do strip when calling out-orient:

https://github.com/aheckmann/gm/blob/e715cbdaacad21504fc04f6933be5cae1812501e/lib/convenience/autoOrient.js#L26-L30

Replacing obj.autoOrient() with obj.out('-auto-orient') should work. Note though that the code mentions it does this because of EXIF tags, but I guess imagemagick should be smart enough to figure this out itself?