3

what I'm trying to achieve is to pull a simple graphic from a webserver and use imagemagick to change a few colors so that I can then further use this image.

This is the imagemagick portion:

convert traffic.png -transparent "rgb(240,240,240)" traffic2.png
convert traffic2.png -fill "rgb(200,200,200)" -opaque black traffic2.png
convert traffic2.png -fill "rgb(200,200,200)" -opaque "rgb(0,200,0)" traffic2.png
convert traffic2.png -fill "rgb(200,200,200)" -opaque "rgb(0,130,0)" traffic2.png
convert traffic2.png -fill "rgb(200,200,200)" -opaque "rgb(150,150,255)" traffic2.png
# convert traffic2.png -fill "rgb(200,200,200)" -opaque "rgb(0,0,255)" traffic2.png

The problem I'm having is with the line that's currently commented out. What it should do in my opinion is change all occurrences of that blue to the same grey as specified, which it also does, but as soon as this line gets executed the previously transparent background turns into a solid color as well. Seeing how the syntax is the same I really don't know why this is happening. It works just fine when I try these commands on my local machine (OS X), but under Debian on my Raspberry Pi something seems to get in the way.

  • Can you provide us with the original traffic.png image? – slm Jul 20 '13 at 4:42
  • Ah of course, sorry. Link – Kilian Jul 20 '13 at 9:32
  • 1
    This works for me as well on Fedora 14 using version 6.6.4-1 2011-11-03 Q16 of imagemagick. What's your version of convert? convert --version. When I say it "works" the 6th command returns a traffic2.png file that's background is transparent. Is that your definition of "works" too? Also works on CentOS 6, 6.5.4-7 2012-05-07 Q16. – slm Jul 20 '13 at 12:32
  • 1
    Doesn't work for me on Ubuntu 12.10, convert version, 6.7.7-10 2012-08-17 Q16. Same problem as you reported. I'd look to the imagemagick issue tracker to see if the problem has been reported there. – slm Jul 20 '13 at 12:41
  • 1
    I think this might be related: "Note that since IM 6.7.5.5 probably through 6.7.6.7, colorspaces RGB and sRGB have undergone changes. Before that, RGB meant sRGB (non-linear) and sRGB (meant linear). Afterwards it was corrected so RGB was linear and sRGB was non-linear. So if you are now using a current IM version and change to -colorspace RGB you are now converting your image to linear colors. But rgb(192,192,192) is likely sRGB (non-linear), and so may not match your image any longer since you made it linear." - imagemagick.org/discourse-server/viewtopic.php?f=1&t=21204 – slm Jul 20 '13 at 15:25
2

I think your issue is as we discussed in the comments under your question, specifically a change that was made between IM 6.6.X and 6.7+. Your commands worked for me on Fedora 14 and CentOS 5 & 6, but not on Ubuntu 12.10.

  • F14 (6.6.4-1 2011-11-03 Q16) - worked
  • CentOS 6 (6.5.4-7 2012-05-07 Q16) - worked
  • Ubuntu 12.10 (6.7.7-10 2012-08-17 Q16) didn't work

I found this bit in the IM documentation, titled: ImageMagick v6 Examples -- Color Basics and Channels. This blurb is what caught my eye in section: "Replacing Colors in Images":

However as of IM v6.2.7, this operator is limited by the "-channel" setting. As such, to convert a color (say blue) to transparency, you will need to specify a "-channel" to include the alpha channel to make colors transparent. You will also need to ensure the image has a 'matte' or alpha channel enabled, to hold the transparency information.

With this new information I converted your 6th command to this:

$ convert traffic2.png -transparent "rgb(0,0,255)" traffic2.png

And it appears to have worked. The OP has confirmed that this solved his issue!

old command

         ss of bad traffic2.png

new command

         ss of good traffic2.png

  • 1
    I thank you heaps for putting so much time into solving this relatively small issue and even more for pointing out to me exactly where the problem resides. Your solution works just fine and everything is grand. – Kilian Jul 20 '13 at 21:39
  • @kiliankoe - awesome. Thank you for your kind words! – slm Jul 20 '13 at 23:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.