replacing colours

Post questions on how to use or achieve an effect in Inkscape.
Lars_Bylund
Posts: 7
Joined: Mon Nov 28, 2011 9:35 am

replacing colours

Postby Lars_Bylund » Tue May 29, 2012 8:25 pm

Is there an 'easy' way to replace, for example, all nuances of yellow colors in an image with the 'same' nuances of red?

f ex (and this is probably not correct)

yellow :fff0004f fff7476f
red :ff0004ff ff7476ff

I know there could be another forum for this, and if you know of any other forum that deals with vector graphics in general, or another program, or small script or something, please let me know.

command-lineish stuff are welcome, since the next step is to batch process a lot of files.

Lars

llogg
Posts: 443
Joined: Tue Mar 11, 2008 7:30 am

Re: replacing colours

Postby llogg » Tue May 29, 2012 9:00 pm

Open your svg file in a text editor and simply do a search and replace for those color codes.

Lars_Bylund
Posts: 7
Joined: Mon Nov 28, 2011 9:35 am

Re: replacing colours

Postby Lars_Bylund » Tue May 29, 2012 10:30 pm

llogg wrote:Open your svg file in a text editor and simply do a search and replace for those color codes.


I have to do it in around 3000 images thou, so that's not an option, I need something automated.

User avatar
Xav
Posts: 1209
Joined: Fri May 08, 2009 1:18 am
Location: UK
Contact:

Re: replacing colours

Postby Xav » Tue May 29, 2012 11:34 pm

Are you on Windows? Or Linux/MacOS?

If it's the latter, I suggest looking into "sed" (or "awk" for even more power) for doing command-like search-and-replace operations on a whole load of files. If you're on Windows the you can install Cygwin in order to get a Unixy command line with sed.

*EDIT*
From one of your other posts it looks like you're already familiar with sed. If that won't do what you want, can you explain a little more about what you need.
Co-creator of The Greys and Monsters, Inked - Inkscape drawn webcomics
Web SiteFacebookTwitter

Uktrunie
Posts: 154
Joined: Sun Jul 18, 2010 4:48 am

Re: replacing colours

Postby Uktrunie » Wed May 30, 2012 9:50 pm

Well, there's an extension, under Extensions > Color > Replace color. But obviously in just one file at a time...

Also, I believe Inkscape comes with it's own version of Python (in Inkscape\python directory). So you might get lucky there as Python has a lot of power. So the "easy" way would be to create a script like this (easier because you have to copy-paste :) ):

Code: Select all

import glob

colors = [{'color': '#0000ffff', 'replace': '#0000ff00'},
          {'color': '#ffffffff', 'replace': '#00000000'}
         ]

for f in glob.glob('d:/MyFiles/*.svg'):
  print f
  fh = open(f, 'r+')
  data = fh.read()
  for c in colors:
    data = data.replace(c['color'], c['replace'])
  fh.seek(0);
  fh.write(data)
  fh.close()



You save that file into Inkscape\python with a "py" extension, say "replace.py", and then double click the python.exe file and write "import replace" and that would be it.

Hope it helps.

EDIT: btw, you might want to skip the last "ff" (alpha channel) as it seems that it's not stored in the way I believed, so you would replace the RGB part only.


Return to “Help with using Inkscape”