Page 1 of 1

Replacing a color with transparency stopped working?

Posted: 2013-08-14T04:07:47-07:00
by joew
Hello,

A year ago, I wrote a script which contained the following command to replace white by transparency:

Code: Select all

convert combined.png \
  \( \
   stanzmuster.ai \
   -resample 600x600 \
   -alpha set -channel RGBA -fuzz 1% -fill none \
   -floodfill +4000+800 white \
   -floodfill +4000+3200 white \
   -floodfill +4000+5000 white \
  \) \
  -composite \
  out.png
This worked fine with those old versions of IM. But it stopped working when I upgraded my distro.

I also tried

Code: Select all

convert stanzmuster.ai -alpha Set -channel RGBA -fuzz 1% -fill none -opaque white sm.png
as well as

Code: Select all

convert stanzmuster.ai -alpha Set -channel RGBA -fuzz 1% -fill none -transparent white sm.png
but none of them seems to have any effect. I also tried to use "#ffffff" instead of "white" but again, to no avail.

Any ideas?

PS:
$ convert --version
Version: ImageMagick 6.7.8-8 2013-03-18 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features: OpenMP

Re: Replacing a color with transparency stopped working?

Posted: 2013-08-14T04:24:30-07:00
by snibgo
It's hard to diagnose without the source images. To turn white pixels transparent, use "-transparent white". See http://www.imagemagick.org/script/comma ... ransparent

I don't have v6.7.8, but it works in v6.7.9 and more recent versions.

Test:

Code: Select all

convert -size 1x1 xc:White xc:Black +append -transparent white txt:
The result should be:

Code: Select all

# ImageMagick pixel enumeration: 2,1,65535,srgba
0,0: (65535,65535,65535,    0)  #FFFFFFFFFFFF0000  srgba(255,255,255,0)
1,0: (    0,    0,    0,65535)  #000000000000  black
For your final command, try:

Code: Select all

convert stanzmuster.ai -fuzz 1% -transparent white sm.png

Re: Replacing a color with transparency stopped working?

Posted: 2013-08-14T05:22:27-07:00
by joew
convert -size 1x1 xc:White xc:Black +append -transparent white txt:
Such simple commands work for me too. Outputting to txt: is a nice feature, btw!
For your final command, try:
Yes, I tried this also, but it did not work.

I guess the problem is with the input file. When outputting to txt:, I get something like:

Code: Select all

439,33: (    0,    0, 2313,    0,65535)  #0000000009090000  cmyka(0,0,9,0,1)
476,33: (    0,    0,    0,    0,65535)  #0000000000000000  cmyka(0,0,0,0,1)
Notice the cmyka? Looks like the -channel RGBA is ignored?

Re: Replacing a color with transparency stopped working?

Posted: 2013-08-14T05:41:18-07:00
by snibgo
As I say, it's hard to diagnose without the source images.

You are compositing a CMYK image over a RGB image. I don't know exactly what IM will do. It's probably better for you to explicitly convert the CMYK image to RGB, using "-colorspace sRGB", eg:

Code: Select all

convert stanzmuster.ai -colorspace sRGB -fuzz 1% -transparent white sm.png

Re: Replacing a color with transparency stopped working?

Posted: 2013-08-14T05:55:40-07:00
by joew
It's probably better for you to explicitly convert the CMYK image to RGB, using "-colorspace sRGB", eg:
Yes, that works!

Thanks!