Replacing a color with transparency stopped working?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
joew
Posts: 42
Joined: 2012-08-23T01:19:56-07:00
Authentication code: 67789

Replacing a color with transparency stopped working?

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Replacing a color with transparency stopped working?

Post 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
snibgo's IM pages: im.snibgo.com
joew
Posts: 42
Joined: 2012-08-23T01:19:56-07:00
Authentication code: 67789

Re: Replacing a color with transparency stopped working?

Post 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?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Replacing a color with transparency stopped working?

Post 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
snibgo's IM pages: im.snibgo.com
joew
Posts: 42
Joined: 2012-08-23T01:19:56-07:00
Authentication code: 67789

Re: Replacing a color with transparency stopped working?

Post by joew »

It's probably better for you to explicitly convert the CMYK image to RGB, using "-colorspace sRGB", eg:
Yes, that works!

Thanks!
Post Reply