Change color in svg file through command line (inkscape) - command-line

I have an .svg file with only one color. I want to change this color to another and export it through command line. (I have to do it about 100 times, so doing it by hand doesn't work.) I use Inkscape at the moment.
I am able to change the background color and export with this command:
inkscape -f name.svt -e output_name.png -b #000080
But I cannot find the way to change the normal color.
I find this verb:
org.inkscape.color.replacecolor
But I don't know, how to add the color I want to use, somewhere I read, that I cannot add variables to verbes, but in that case how can be this verb used?
Thank you in advance.

This is not a general purpose solution, but since a SVG file is just XML internally, if your SVG file is simple enough you might be able to get away with a simple sed replacement. For example the following replaces #000000 (black) with #ffffff (white):
sed -e "s/#000000/#ffffff/" input.svg >output.svg
This may or may not be good enough for your needs.

Although inkscape is a powerful tool, I think you will have more luck (control) with xlst tranformations. This will allow you to do anything to an xml file rather than parsing the file as an svg image and relying on the available API. You might take a look at a tool like xsltproc for this.

Related

ghostscript not creating exact images

I am running below script to create images from postscript file, the images are coming but on first page watermark is not there.
gs -dUseCIEColor -dNOPAUSE -sDEVICE=jpeg -dFirstPage="1" -dLastPage=2 -sOutputFile=outputImage_%0d_A.gif -dJPEGQ=100 -r300 -q inputFile.ps -c quit;'
I am giving the link of ps file which i am using.
http://speedy.sh/Y7vWj/inputFile.ps
Can anybody please help!!!!
Thanks in advance...
OK you haven't stated what version of Ghostscript you are using, nor have you been very clear about what is missing. By 'watermak' do you mean the dark grey text 'PAULDAVIS' written diagonally across the very dark grey rectangle ?
If so then I can see that using the current version of Ghostscript and your command line, its not missing
A few observations on your command line:
-dUseCIEColor - Don't use this unless you know exactly what you are doing and why you want this, I'm guessing you don't (because you have not set any Color Rendering Dictionary). With this you get very dark grey text which is nearly invisible against the very dark grey rectangle. Not surprising since this relates to colour management.
You've set the device to jpeg, but you've set the output file to have a .gif extension.
You are using -dFirstPage and -dLastPage which have no effect when the input is not PDF (though this is added as a new feature in unreleased code).
You've set FirstPage=1 and LastPage=2 on a 2 page file.....
You have set -dFirstPage="1", which isn't going to work for any code which parses and uses it. The quotes won't work.
I'd recommend you do not set -q or -dQUIET when trying to diagnose problems, telling Ghostscript to be quiet will potentially mean you miss useful information.
-c quit; -c means 'process the next part of the command line as PostScript'. But quit; isn't valid PostScript (the semicolon should not be present) and will throw a PostScript error. If you want GS to exit after processing, consider simply using -dBATCH.

Editing a Text File from Matlab

I'm still getting used to Matlab, and not sure if this is possible using Matlab or not, but it's just something that popped into my head that I thought could be interesting.
Is there any way to edit the contents of a text file in Matlab?
Moreover, is there any way to edit specific parts of the text file without altering the rest?
To elaborate, let's say I had a text file that was several lines long. For instance:
This is a hypothetical text file.
The cat chased a mouse.
The mouse ran into a hole.
The cat tried to paw at the mouse.
The mouse waited in the hole until the cat got bored.
The mouse came back out when the cat left.
Is there any way to use Matlab to exclusively edit, say, line 6 and change it from "The mouse waited in the hole until the cat got bored" to "The mouse fell asleep and the cat got bored", without having to change the rest of the file?
I know of several methods to read and display contents of text files using Matlab, but I'm not sure if there's any way to actually edit the text files in Matlab.
Thanks!
As far as I know, you will always have to read the file line by line (for instance into a cell-array) and edit it as you need. After that, you write a new file or overwrite the old one.
Of course, you can encapsulate this procedure and then call you own function like
manipulateFile(lineNumber, newLineText)
Some commands that may come in handy are fopen, fscanf, textread, fprintf, and fclose.

how to remove characters from a font file?

i've downloaded the DejaVu open source font and want to use it ad a WebFont, but even when converting it, i get a large file, and because the website i'll use will be only in few languages (arabic, french, amazigh) then, i dont need some characters.
so is there a way to browse the font file and delete the unnecessary range of unicode characters that i'll not need?
Using FontForge, you may open Element->Font Info->Unicode Ranges. You will see all available ranges and you can select a whole Unicode range with a single click. Then, you can tune your selection and delete using Encoding->Detach & Remove Glyphs.
Also, you can use Edit->Select->Select by Script.
The easiest method I found is to use pyftsubset tool from FontTools. Here's an example:
$ pyftsubset NotoSans-Regular.ttf \
--unicodes=U+0400-045F,U+0490-0491,U+04B0-04B1,U+2116 \
--output-file=NotoSans-Regular.cyrillic.woff2 \
--flavor=woff2
Note: woff2 output requires Brotli.
I wrote a simple script around it which automates the whole process including generation of a CSS file after splitting the font file. You may find it here: https://github.com/johncf/ttf2web

Inkscape command line programming

I'd like to be able to derive new images from a pre-existing image from the command line. To do that, I'd turn on/off specific layers that have portions of the image and then save the resulting image to a file. However, while I can see a number of commands listed in the help to manipulate layers, I don't see any that would allow one to select a specific one and turn it on/off.
If what you want to do can be achieved by deleting a few unwanted elements by their id (say, layer17 and layer4711), you can do it this way:
inkscape image.svg \
--select=layer17 --verb=EditDelete \
--select=layer4711 --verb=EditDelete \
--verb=FileSave --verb=FileClose
Note that this will overwrite image.svg with the result, so if you're scripting this, be sure to work on a copy rather than your originals.
inkscape image.svg --export-id-only --export-id=layer17 --export-png=image.png --export-width=100 --export-height=100
On a Mac you might have to do:
/Applications/Inkscape.app/Contents/Resources/bin/inkscape --without-gui --file=image.svg --export-id-only --export-id=layer17 --export-png=image.png --export-width=100 --export-height=100
I've written an Inkscape extension for work like this. It outputs one file for each option layer found. It will also show various layer combinations as needed. Scriptable as well. I call it the SLiCk Layer Combinator:
https://github.com/juanitogan/slick

showing differences within a line in diff output

This StackOverflow answer has an image of KDiff3 highlighting intra-line differences. Does someone know of a tool which can show the same (ex, via color) on the command line?
Another way to think of this is wanting to diff each difference in a patch file.
I don't know if this is sufficiently command line for your purpose, but vimdiff can do this (even does colour). See for example the image in this related question.
I tried all the tools I found: wdiff, dwdiff, kdiff3, vimdiff to show the difference between two long and slightly different lines. My favourite is diff-highlight (part of git contrib)
it supports diff format - great advantage over tools requiring two files like (dwdiff), e.g. if you need to visualize the output of unit tests
it highlights with black+white or with color if you connect it to colordiff
highlights characterwise - helpful for comparing long lines without spaces (better than wdiff)
Installation
On Ubuntu, you probably already have it as part of git contrib (installed within the git deb package).
Copy or link it into your ~/bin folder from /usr/share/doc/git/contrib/diff-highlight/diff-highlight
Usage example
cat tmp.diff | diff-highlight | colordiff
Result:
Another intuitive way to see all word-sized differences (though not side-by-side) is to use wdiff together with colordiff (you might need to install both). An example of this would be:
wdiff -n {file-A} {file-A} | colordiff
You can optionally pipe this into less -R to scroll through the output (-R is used to show the colors in less).
I had a similar problem and wanted to avoid using vimdiff. I found dwdiff (which is available in Debian) to have several advantages over wdiff.
The most useful feature of dwdiff is that you can customise the delimiters with -d [CHARS], so it's useful for comparing all kinds of output. It also has color built in with the -c flag.
You might be able to use colordiff for this.
In their man page:
Any options passed to colordiff are
passed through to diff except for the
colordiff-specific option 'difftype',
e.g.
colordiff --difftype=debdiff file1
file2
Valid values for 'difftype' are: diff,
diffc, diffu, diffy, wdiff, debdiff;
these correspond to plain diffs,
context diffs, unified diffs,
side-by-side diffs, wdiff output and
debdiff output respectively. Use these
overrides when colordiff is not able
to determine the diff-type
automatically.
I haven't tested it, but the side-by-side output (as produced by diff -y file1 file2) might give you the equivalent of in-line differences.
ccdiff is a convenient dedicated tool for the task. Here is what an example may look like with it:
By default, it highlights the differences in color, but it can be used on a console without color support too.
The package is included in the main repository of Debian:
ccdiff is a colored diff that also colors inside changed lines.
All command-line tools that show the difference between two files fall short in showing minor changes visuably useful. ccdiff tries to give the look and feel of diff --color or colordiff, but extending the display of colored output from colored deleted and added lines to colors for deleted and addedd characters within the changed lines.