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 »

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: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Change image color

Post by fmw42 »

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: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Change image color

Post by fmw42 »

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 »

Also confirmed with 7.0.5.9 on cygwin (and breaks lots of scripts)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Change image color

Post by fmw42 »

I can confirm this also on 7.0.5.9 Mac OSX
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Change image color

Post by magick »

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 »

Thank you for consider it.
shoansa
Posts: 15
Joined: 2017-07-18T00:12:17-07:00
Authentication code: 1151

Re: Change image color

Post by shoansa »

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: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Change image color

Post by fmw42 »

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: 15
Joined: 2017-07-18T00:12:17-07:00
Authentication code: 1151

Re: Change image color

Post by shoansa »

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: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Change image color

Post by fmw42 »

-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?
shoansa
Posts: 15
Joined: 2017-07-18T00:12:17-07:00
Authentication code: 1151

Re: Change image color

Post by shoansa »

Hi Fred,

Thanks, that work.

With the updated version of IM, output image gets pixelated. Below is the detail.

Version= ImageMagick-7.0.8-Q16
OS= Windows 7, 64 bit
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Change image color

Post by fmw42 »

Please show your input and output images and the command you used. Also what is the exact version of ImageMagick 7.0.8.x

If this was the last command I showed, then it seems to work fine for me on IM 7.0.8.61 Q16 Mac OSX.

Image

Unix syntax:

Code: Select all

magick -respect-parenthesis \
\( input_text.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_text.png \) \
null:
Image
shoansa
Posts: 15
Joined: 2017-07-18T00:12:17-07:00
Authentication code: 1151

Re: Change image color

Post by shoansa »

Version
Version: ImageMagick 7.0.8-60 Q16 x64 2019-08-10 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Visual C++: 180040629
Features: Cipher DPC Modules OpenCL OpenMP(2.0)
Delegates (built-in): bzlib cairo flif freetype gslib heic jng jp2 jpeg lcms lqr lzma openexr pangocairo png ps raw rsvg tiff webp xml zlib

Command:
magick -respect-parenthesis ( input.png -fuzz 99% -fill rgb(225,225,225) -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:

Input
Image

Output
Image

Expected output
Image

The expected output is generated from the old version of IM (ImageMagick-6.9.1-Q16-HDRI)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Change image color

Post by fmw42 »

I get your same bad result on IM 7.0.8.61 Q16 HDRI Mac OSX with the following command:

Code: Select all

magick -respect-parenthesis \
\( 6214291349a70-af1a-431a-8186-0ced1d8e8c4d.png -fuzz 50% -fill "rgb(225,225,225)" -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_text.png \) \
null:
Likewise using IM 6.9.10.61 and 6.9.1.7 Q16 Mac OSX (both non-HDR) with

Code: Select all

convert -respect-parenthesis \
\( 6214291349a70-af1a-431a-8186-0ced1d8e8c4d.png -fuzz 50% -fill "rgb(225,225,225)" -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_text6.png \) \
null:
I am not sure how you got a better result because your are using -fuzz to do the color change. That will produce stair stepping unless you use some blur to antialias.
Post Reply