1
votes

I am in the process of creating several images, containing text and diagrams, using imagemagick and other tools.

At some point I realized that, even though the same instructions were being used in batch with little changes, the colors - defined very precisely by their hex value - change from image to image!

Here is an example (no input file needed) that gives reproduceably wrong (or at least unexpected) results on my machine (Ubuntu 14.04, ImageMagick 6.7.7-10 2017-07-31) [edited per fmw42's suggestion]

convert   -size 66x46 -bordercolor "#a0a0a0" -border 2 xc:White -gravity Center -fill "#a0a0a0" -weight 700 -pointsize 24 -annotate 0 "0"  a_1.png
convert  -size 326x46 -bordercolor "#f0f0f0" -border 2 xc:White -gravity West -fill "#000000" -weight 700 -pointsize 14 -annotate +10+0 "4-Fluoroacetophenone"  a_2.png
montage  -colorspace sRGB a_1.png a_2.png  -tile 2x1 -mode Concatenate -set colorspace sRGB a_3.png

convert  -size 66x46 -bordercolor "#a0a0a0" -border 2  xc:White -gravity Center -fill "#a0a0a0" -weight 700 -pointsize 24 -annotate 0 "CN"  b_1.png
convert -size 326x46 -bordercolor "#f0f0f0" -border 2  xc:White -gravity West -fill "#000000" -weight 700 -pointsize 14 -annotate +10+0 "trans-3-dimethylaminoacrylonitrile"  b_2.png
montage  -colorspace sRGB b_1.png b_2.png  -tile 2x1 -mode Concatenate -set colorspace sRGB b_3.png

(I have left the original text variables, since I haven't been able to understand what triggers the change of color, and different rendered words give different results)

The 6 istructions above create these 6 images:

a_1.png   a_2.png   a_3.png
b_1.png   b_2.png   b_3.png

that appear like this:

enter image description here

As you can see, while a_1 and b_1 share the same color - and a_2 and b_2 as well - a_3 and b_3 (which are composite of a_1+a_2 and b_1+b_2) have different colors! Having added explicit specification of colorspace hasn't helped.

(This is not an artifact of having put the 6 pictures in a single file. The color difference is apparent in the separate files as well)

What is causing this? How can I get consistent colors in imagemagick? As I'm using visual color codes to convey information, I need palettes that I can rely on.


Edit: this does't happen (i.e. colors are consistent) with ImageMagick 6.8.9-9 Q16 x86_64 2017-07-31 that unfortunately isn't the version I have on my production machine.

I'm not removing the question as finding a solution within ImageMagick 6.7.7 would help. Or is it just a (known) bug and so the only solution is upgrading?

2

2 Answers

1
votes

Your ImageMagick 6.7.7-10 2017-07-31 has been patched numerous times and the latest patch was 2017-07-31. There have been reports of other issues with the patch. So I suspect it had a bad patch and you should inquire of your Linux distribution.

Note that proper Imagemagick syntax for raster images is to read the input image first (or create it) before any settings and operators. So properly, your syntax should be

convert -size 66x46 xc:White -bordercolor "#a0a0a0" -border 2  -gravity Center -fill "#a0a0a0" -weight 700 -pointsize 24 -annotate 0 "0"  a_1.png

IM 6 is forgiving, so it likely will not matter. But IM 7 is not as forgiving.

The -set colorspace sRGB is likely un-necessary in your command, but should not hurt. But if used, should be properly placed after creating your input image.

0
votes

Using Imagemagick 6.9.9.5 Q16 Mac OSX (2017-08-04) and Imagemagick 7.0.6.5 Q16 HDRI, proper syntax should be:

IM 6

convert  -size 66x46 xc:White -bordercolor "#a0a0a0" -border 2 -gravity Center -fill "#a0a0a0" -weight 700 -pointsize 24 -annotate 0 "0"  a_1.png
convert  -size 326x46 xc:White -bordercolor "#f0f0f0" -border 2  -gravity West -fill "#000000" -weight 700 -pointsize 14 -annotate +10+0 "4-Fluoroacetophenone"  a_2.png
montage  a_1.png a_2.png  -tile 2x1 -mode Concatenate -set colorspace sRGB a_3.png

convert  -size 66x46 xc:White -bordercolor "#a0a0a0" -border 2  -gravity Center -fill "#a0a0a0" -weight 700 -pointsize 24 -annotate 0 "CN"  b_1.png
convert  -size 326x46 xc:White -bordercolor "#f0f0f0" -border 2  -gravity West -fill "#000000" -weight 700 -pointsize 14 -annotate +10+0 "trans-3-dimethylaminoacrylonitrile"  b_2.png
montage  b_1.png b_2.png  -tile 2x1 -mode Concatenate -set colorspace sRGB b_3.png

IM 7

magick  -size 66x46 xc:White -bordercolor "#a0a0a0" -border 2 -gravity Center -fill "#a0a0a0" -weight 700 -pointsize 24 -annotate 0 "0"  a_1.png
magick  -size 326x46 xc:White -bordercolor "#f0f0f0" -border 2  -gravity West -fill "#000000" -weight 700 -pointsize 14 -annotate +10+0 "4-Fluoroacetophenone"  a_2.png
magick montage  -colorspace sRGB a_1.png a_2.png  -tile 2x1 -mode Concatenate -set colorspace sRGB a_3.png

magick  -size 66x46 xc:White -bordercolor "#a0a0a0" -border 2  -gravity Center -fill "#a0a0a0" -weight 700 -pointsize 24 -annotate 0 "CN"  b_1.png
magick  -size 326x46 xc:White -bordercolor "#f0f0f0" -border 2  -gravity West -fill "#000000" -weight 700 -pointsize 14 -annotate +10+0 "trans-3-dimethylaminoacrylonitrile"  b_2.png
magick montage  -colorspace sRGB b_1.png b_2.png  -tile 2x1 -mode Concatenate -set colorspace sRGB b_3.png

For both I get:

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

Is this correct? Do you get something different using my commands?