Reputation: 45
I have a script that uses ImageMagick to composite two images together. It worked fine with ImageMagick v6, but outputs broken images with v7 (ImageMagick 7.0.8-68 Q16 x86_64 2020-01-14 on macOS, to be precise).
The two input images both use a CMYK colour profile, which they both have embedded, but I also have as a seperate file. I want the output file to use the same colour profile. Compositing the images together using ImageMagick v7 results in a broken image where the colour space is changed to RGB, with the CMY channels mapped to RGB and the K channel discarded (so the colours look very obviously wrong!). Performing other operations on these files, such as cropping, outputs results that retain the colour profile and CMYK colour space as intended; as far as I can tell, it's just the behaviour of composite
that has changed.
I was originally using the following command:
convert -profile USWebCoatedSWOP.icc under.jpg -profile USWebCoatedSWOP.icc over.jpg -gravity center -composite -profile USWebCoatedSWOP.icc comp.jpg
This works under v6, but is broken under v7. Since the images have the colour profile embedded, I wondered if some kind of colour space conversion was happening because I was also providing the profile file in the command, so I tried a few other variations:
# No external profiles specified:
convert under.jpg over.jpg -gravity center -composite comp.jpg
# Embedded input profiles implicit, output profile specified:
convert under.jpg over.jpg -gravity center -composite -profile USWebCoatedSWOP.icc comp.jpg
# Output profile specified twice, as a from–to conversion:
convert under.jpg over.jpg -gravity center -composite -profile USWebCoatedSWOP.icc -profile USWebCoatedSWOP.icc comp.jpg
All of these however result in the same output. (They also result in consistent output under v6, except in that case, the output is always correct!) Adding -colorspace CMYK
has no effect except to make the broken image slightly washed out. Adding -set colorspace CMYK
results in a corrupt image.
Something has apparently changed in how ImageMagick handles colour profiles in composite operations between v6 and v7 – but what? Nothing immediately stands out in the changelogs.
Relevant portions from identify -verbose
. Input files have:
Image: under.jpg
Format: JPEG (Joint Photographic Experts Group JFIF format)
Mime type: image/jpeg
Class: DirectClass
Geometry: 1630x2220+0+0
Resolution: 600x600
Print size: 2.71667x3.7
Units: Undefined
Colorspace: CMYK
Type: ColorSeparation
…
Properties:
date:create: 2020-08-29T13:13:02+00:00
date:modify: 2020-08-29T12:39:46+00:00
icc:copyright: Copyright 2000 Adobe Systems, Inc.
icc:description: U.S. Web Coated (SWOP) v2
jpeg:colorspace: 4
jpeg:sampling-factor: 1x1,1x1,1x1,1x1
signature: d8e1a18efe471b7a131e661ea31e0b02aed6cb9e6555254781fc9df5352f2d6c
Profiles:
Profile-icc: 557168 bytes
…
Broken output file from v7 has:
Image: comp.jpg
Format: JPEG (Joint Photographic Experts Group JFIF format)
Mime type: image/jpeg
Class: DirectClass
Geometry: 1630x2220+0+0
Resolution: 600x600
Print size: 2.71667x3.7
Units: Undefined
Colorspace: sRGB
Type: TrueColor
…
Properties:
date:create: 2020-08-29T13:35:01+00:00
date:modify: 2020-08-29T13:35:01+00:00
icc:copyright: Copyright 2000 Adobe Systems, Inc.
icc:description: U.S. Web Coated (SWOP) v2
jpeg:colorspace: 2
jpeg:sampling-factor: 1x1,1x1,1x1
signature: f1ef274bc6f6f631a406ea3e5c25691faa50ea99ff14ab56ed7b80431f2e64a4
Profiles:
Profile-icc: 557168 bytes
…
Correct output file from v6 has:
Image: comp.jpg
Format: JPEG (Joint Photographic Experts Group JFIF format)
Mime type: image/jpeg
Class: DirectClass
Geometry: 1630x2220+0+0
Resolution: 600x600
Print size: 2.71667x3.7
Units: Undefined
Colorspace: CMYK
Type: ColorSeparation
… Properties:
date:create: 2020-08-29T13:25:44+00:00
date:modify: 2020-08-29T13:24:12+00:00
icc:copyright: Copyright 2000 Adobe Systems, Inc.
icc:description: U.S. Web Coated (SWOP) v2
jpeg:colorspace: 4
jpeg:sampling-factor: 1x1,1x1,1x1,1x1
signature: 457347556af05e75fd5cc65f8c1cd1c94dae1ac6fb574c103dc09d8744877928
Profiles:
Profile-icc: 557168 bytes
…
Channel statistics for the RGB channels in the broken output exactly match those for the CMY channels in the correct output.
Edit: Per fmw42's comment, I've also tried the stricter syntax of v7:
magick under.jpg -profile USWebCoatedSWOP.icc over.jpg -profile USWebCoatedSWOP.icc -gravity center -composite -profile USWebCoatedSWOP.icc comp.jpg
However, this still produces a broken image. Here are test images with the profile embedded (smaller than the real images I'm using, but still exhibiting the same problem):
Upvotes: 0
Views: 531
Reputation: 53101
These two command work fine for me with ImageMagick using IM 6.9.11.28 and IM 7.0.10.28 Q16 Mac OSX Sierra. Both produce CMYK results and contain the cmyk profile. I suspect your IM 7 version is old and had a bug that since has been corrected. The profiles are carried from the input to the ouput.
IM 6
convert under.jpg over.jpg -gravity center -compose over -composite result6.jpg
IM 7
magick under.jpg over.jpg -gravity center -compose over -composite result7.jpg
Upvotes: 1