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?".
Rye
Posts: 158 Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789
Post
by Rye » 2014-06-20T09:55:12-07:00
So I have this picture:
And want to repace all colours EXCEPT #ffffff with #A7A7AF
I hope this can be done "pixle perfect".
Thanks in advance.
Last edited by
Rye on 2014-06-20T12:14:33-07:00, edited 2 times in total.
fmw42
Posts: 25562 Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA
Post
by fmw42 » 2014-06-20T10:09:54-07:00
Unfortunately, your image has no pure white #ffffff
If it did, then
Code: Select all
convert "Snow_Sharo 001.gif" -fill "#A7A7AF" +opaque "#ffffff" result.gif
If you want to use a fuzz value to catch the close to white values then try
Code: Select all
convert "Snow_Sharo 001.gif" -fuzz 5% -fill "#A7A7AF" +opaque "#ffffff" result.gif
Adjust the fuzz value as desired
Rye
Posts: 158 Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789
Post
by Rye » 2014-06-20T12:03:16-07:00
the second command seems to do nothing to my picture (I replaced "show:" with result.gif).
Am I doing something wrong ?
I also played around with the fuzz value as instructed, however the change was still - nothing...
This command *did* something, however still not as good as I wished it to be:
Code: Select all
convert "001.gif" -fill white +opaque #A7A7AF -transparent white result.gif
Last edited by
Rye on 2014-06-20T12:10:22-07:00, edited 1 time in total.
fmw42
Posts: 25562 Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA
Post
by fmw42 » 2014-06-20T12:08:49-07:00
Sorry, I forgot to replace show: with a filename. Edited now to fix that.
If you are on Windows replace % with %%.
Code: Select all
convert "Snow_Sharo 001.gif" -fuzz 5%% -fill "#A7A7AF" +opaque "#ffffff" result.gif
Note the double quotes about your file name, since it has spaces in it. I am not sure how Windows handles that.
see
http://www.imagemagick.org/Usage/windows/
Note again, that the image you provide has not perfectly white pixels.
Rye
Posts: 158 Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789
Post
by Rye » 2014-06-20T13:04:49-07:00
using a second % doesn't help.
How can I find the version etc. ?
fmw42
Posts: 25562 Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA
Post
by fmw42 » 2014-06-20T14:13:31-07:00
Post your exact command and the input image.
To get the IM version,
Rye
Posts: 158 Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789
Post
by Rye » 2014-06-20T14:38:36-07:00
Code: Select all
convert 001.gif -fuzz 5%% -fill "#A7A7AF" +opaque "#ffffff" 002.gif
This does nothing to the image posted above (have you found a satisfactionary code that works with the above image ?)
IMGMagick version:
Version: ImageMagick 6.8.3-4 2013-02-20 Q16
http://www.imagemagick.org
Copyright: Copyright (C) 1999-2013 ImageMagick Studio LLC
Features: DPC OpenMP
Delegates: bzlib fontconfig freetype jng jp2 jpeg lcms lzma pango png ps tiff x xml zlib
fmw42
Posts: 25562 Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA
Post
by fmw42 » 2014-06-20T15:00:17-07:00
Rye wrote: Code: Select all
convert 001.gif -fuzz 5%% -fill "#A7A7AF" +opaque "#ffffff" 002.gif
This does nothing to the image posted above (have you found a satisfactionary code that works with the above image ?)
It has converted your background from #A8A8B0 to #A7A7AF. But there is little (visual) difference in that color change.
try
Code: Select all
convert 001.gif -fuzz 5%% -fill "#FF0000" +opaque "#ffffff" 002.gif
and you will see that your background is now red
Rye
Posts: 158 Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789
Post
by Rye » 2014-06-20T15:16:19-07:00
Is it possible to define multiple colors that are to be exluded from the replace ?
If I would like to replace any colour except for these three: #F4F4FC #F7F7FF #F9F9FF with let's say #000000.
How'd I do it ?
fmw42
Posts: 25562 Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA
Post
by fmw42 » 2014-06-20T15:58:50-07:00
As long as your image has no (partial or fully) transparent pixels, then do the following
Unix:
Code: Select all
convert yourimage \
-fill none -opaque "#F4F4FC" \
-fill none -opaque "#F7F7FF" \
-fill none -opaque "#F9F9FF" \
\( -clone 0 -fill "#000000" -colorize 100 \) \
+swap -compose over -composite resultimage
Windows:
Code: Select all
convert yourimage ^
-fill none -opaque "#F4F4FC" ^
-fill none -opaque "#F7F7FF" ^
-fill none -opaque "#F9F9FF" ^
( -clone 0 -fill "#000000" -colorize 100 ) ^
+swap -compose over -composite resultimage
Add -fuzz if so desired to get close colors.
Rye
Posts: 158 Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789
Post
by Rye » 2014-06-21T01:40:10-07:00
This outputs:
"convert.exe: invalid argument for option '-colorize': #000000 @ error/convert.c/ConvertImageCommand/969."
snibgo
Posts: 12159 Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK
Post
by snibgo » 2014-06-21T07:33:36-07:00
I think Fred made a typo and meant "-colorize 100" (no quotes needed).
The following Windows BAT script makes a sample file. From this, it makes all colours
except the specified colours into purple. Change "purple" to anything you want.
There may be a simpler method.
Code: Select all
convert ^
-size 20x20 ^
xc:red xc:lime xc:blue xc:#F4F4FC xc:#F7F7FF xc:#F9F9FF xc:khaki ^
+append ^
sample.png
convert ^
sample.png ^
( -clone 0 -fill Purple -colorize 100 ) ^
+swap ^
-alpha set ^
( -clone 1 ^
( -clone 0 +transparent #F4F4FC ) ^
( -clone 0 +transparent #F7F7FF ) ^
( -clone 0 +transparent #F9F9FF ) ^
-delete 0 ^
-evaluate set 0 ^
-layers flatten ^
-negate ^
) ^
-compose Over -composite ^
s1.png
convert ^
s1.png -unique-colors txt:
The final "-unique-colors" is to verify the result.
fmw42
Posts: 25562 Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA
Post
by fmw42 » 2014-06-21T09:59:35-07:00
I think Fred made a typo and meant "-colorize 100" (no quotes needed).
Yes, indeed I made a mistake. Thanks for catching it snibgo. I have fixed my command above.
Rye
Posts: 158 Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789
Post
by Rye » 2014-06-21T11:18:58-07:00
Ok, perfect, now it works
BTW: colorize seems to only "tone" the color down.
Is there a way to make it pitch black (for example) just by once executing this ?