Change image color

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
rpatelob
Posts: 62
Joined: 2017-04-17T22:17:01-07:00
Authentication code: 1151

Change image color

Post by rpatelob » 2017-06-01T03:36:58-07:00

Is this a bug?
I'm trying to change colour of an image. All colours should be changed except transparent.
Please look at the command.

Code: Select all

convert single_color.png -fuzz 20% -fill red +opaque "#00000000" output.png
#or 
convert single_color.png -fuzz 20% -fill red +opaque transparent output.png
It was working on my previous imagemagick version but after upgraded, it seems to be not working.

Version: ImageMagick 7.0.5-9 Q16 x86_64 2017-06-01 http://www.imagemagick.org

User avatar
fmw42
Posts: 24732
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Change image color

Post by fmw42 » 2017-06-01T09:21:23-07:00

They do two different things.

On IM 7, this should work

Code: Select all

magic single_color.png -fuzz 20% -fill red +opaque "#00000000" output.png
or

Code: Select all

magic single_color.png -fuzz 20% -fill red +opaque none output.png
However, in testing it works fine in IM 6.9.8-7 using convert , but does fail in 7.0.5-8 using magick.

The other command with +opaque, changes all colors but red to transparent

User avatar
fmw42
Posts: 24732
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Change image color

Post by fmw42 » 2017-06-01T09:26:55-07:00

I can confirm this bug in IM 7.0.5.8 Mac OS X when compare to IM 6.9.8.7


# create transparent image

Code: Select all

convert logo: -transparent white logot.png
Image

IM 6:

Code: Select all

convert logot.png -fuzz 10% -fill red +opaque none logot_red6.png
Image

IM7: (makes no change to the image)

Code: Select all

magick logot.png -fuzz 10% -fill red +opaque none logot_red7.png
Image

lettermand
Posts: 1
Joined: 2017-06-01T09:31:34-07:00
Authentication code: 1151

Re: Change image color

Post by lettermand » 2017-06-01T09:39:19-07:00

Also confirmed with 7.0.5.9 on cygwin (and breaks lots of scripts)

User avatar
fmw42
Posts: 24732
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Change image color

Post by fmw42 » 2017-06-01T09:47:35-07:00

I can confirm this also on 7.0.5.9 Mac OSX

User avatar
magick
Site Admin
Posts: 10935
Joined: 2003-05-31T11:32:55-07:00

Re: Change image color

Post by magick » 2017-06-01T11:40:31-07:00

Thanks for the problem report. We can reproduce it and will have a patch to fix it in GIT master branch @ https://github.com/ImageMagick/ImageMagick later today. The patch will be available in the beta releases of ImageMagick @ http://www.imagemagick.org/download/beta/ by sometime tomorrow.

rpatelob
Posts: 62
Joined: 2017-04-17T22:17:01-07:00
Authentication code: 1151

Re: Change image color

Post by rpatelob » 2017-06-01T21:51:04-07:00

Thank you for consider it.

shoansa
Posts: 11
Joined: 2017-07-18T00:12:17-07:00
Authentication code: 1151

Re: Change image color

Post by shoansa » 2019-01-15T04:35:50-07:00

It seems that this problem still exists in the latest release of "ImageMagick-7.0.8-Q16". Below are actions performed.

1) magick input.png -fuzz 100% -fill red -opaque white output.png (With this get same output as in input).

2) magick input.png -fuzz 100% -fill red +opaque white output.png (If I change -opaque to +opaque, color get filled on whole image)

Attaching input and expected images.

Input image
Image

expected image
Image

Please help.

User avatar
fmw42
Posts: 24732
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Change image color

Post by fmw42 » 2019-01-15T15:22:39-07:00

Your command should not work. You are trying to change all colors by using -fuzz 100% and your are trying to change white, not black to red. This works fine for me on IM 7.0.8.23 Q16 Mac OSX Sierra, thought I get pure red and not your lighter reddish color.

Code: Select all

magick input.png -fuzz 50% -fill red -opaque black output.png

shoansa
Posts: 11
Joined: 2017-07-18T00:12:17-07:00
Authentication code: 1151

Re: Change image color

Post by shoansa » 2019-01-17T02:58:30-07:00

Thank you Fred to correct me.

One more query, I am trying to combine three commands in one to achieve drop shadow effect in image. Below command used to work in orlder version but not working in current version. Can you please correct me where I am doing wrong? Below is the command.

magick -respect-parentheses ( input.png -fuzz 50% -fill red -opaque black -quality 20 ) ( -clone 0 -background rgb(53,63,124) -shadow 50x1+2+1 ) ( -clone 0 -background black -shadow 30x1-2-1 ) ( -clone 0 -clone 1 -clone 2 -reverse -background none -layers merge -quality 20 +repage +write output.png )

User avatar
fmw42
Posts: 24732
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Change image color

Post by fmw42 » 2019-01-17T15:23:19-07:00

-respect-parentheses apparently was not converted to IM 7. Use -respect-parenthesis. Also you need to add a null: after your last parenthesis. So in Windows IM 7 with ^ as new line characters to make it more readable, try

Code: Select all

magick -respect-parenthesis ^
( input.png -fuzz 50% -fill red -opaque black -quality 20 ) ^
( -clone 0 -background rgb(53,63,124) -shadow 50x1+2+1 ) ^
( -clone 0 -background black -shadow 30x1-2-1 ) ^
( -clone 0 -clone 1 -clone 2 -reverse -background none -layers merge -quality 20 +repage +write output.png ) ^
null:
Does that work the way you want? If not, show us the input and the output and tell us what is wrong?

Post Reply