Replace txt file hex colors in current image

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
Rye
Posts: 158
Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789

Replace txt file hex colors in current image

Post 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 ?
Version: ImageMagick-7.0.7-28-Q16-x64-static http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Replace txt file hex colors in current image

Post by snibgo »

What is the first error message?
snibgo's IM pages: im.snibgo.com
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Replace txt file hex colors in current image

Post 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.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Replace txt file hex colors in current image

Post 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
Rye
Posts: 158
Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789

Re: Replace txt file hex colors in current image

Post 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...)
Version: ImageMagick-7.0.7-28-Q16-x64-static http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
Post Reply