Page 1 of 1

Replace txt file hex colors in current image

Posted: 2017-02-08T03:30:22-07:00
by Rye
So, I'm trying the following:

1.) have a hex.txt with hex values
2.) have a png file where I want to remove said hex (by replacing it w. #000000)

My command looks like this:
@echo off
DEL heximage*
DEL newimage*
DEL hex.txt
cls
SET /P heximage=Drag and drop that contains the hex colors to remove:
copy %heximage% heximage.*
for /F "usebackq skip=1 tokens=3" %%C in (`%IM%convert rose: -depth 8 ^ txt:`) do echo %%C >>x.txt
findstr # x.txt >> hex.txt
DEL heximage.*
DEL x.txt
echo "Now removing Hex colors"
for /F %%c in (hex.txt) do for %%x in (*png) do convert %%x -fill "%%c" -opaque "#000000" %%x

Sadly, this won't replace anything in the picture (despite the hex values def. being in there)
Instead I keep getting error messages to no end.

Ideas on what might be wrong ?

Re: Replace txt file hex colors in current image

Posted: 2017-02-08T07:39:02-07:00
by snibgo
What is the first error message?

Re: Replace txt file hex colors in current image

Posted: 2017-02-08T09:10:09-07:00
by snibgo
Your script is massively inefficient, but I'll ignore that for now.

It won't do what I think you want.
Rye wrote:I want to remove said hex (by replacing it w. #000000)
But you have:
Rye wrote:-fill "%%c" -opaque "#000000"
This will replace #000000 (black) with some other colour.

Re: Replace txt file hex colors in current image

Posted: 2017-02-08T10:49:00-07:00
by fmw42
As snibgo said, you have it backwards. You want

Code: Select all

-fill black -opaque yourhexcolor
see http://www.imagemagick.org/Usage/color_basics/#replace

Re: Replace txt file hex colors in current image

Posted: 2017-02-08T16:02:21-07:00
by Rye
Ok, so the command like that:

Code: Select all

for /F %%c in (hex.txt) do for %%x in (*png) do convert %%x -fill "#000000" -opaque "%%c" %%x
works as advertised.
Further question (this might get messy):

If I now would want a second text file "hexignore.txt" in the same dir, and have imagemagick ignore the colors in that text file:

Would there be... a feasible solution for this ?
(Maybe even requiring a rewrite for the script itself I guess...)