Is there a way to get pixel color in Inkscape using command-line or within extension - svg

So lets say there is some SVG file which might have some bitmap objects as well. What i need is some way to detrmine the color of pixel with coordinates X, Y. Basicly same what "dropper tool" does but calling it from command line or from inkscape python extension.

You can use the inkscape binary to export an image, and then use a scripting language (such as PHP) to do the sampling:
inkscape --without-gui --export-png=myfile.png --export-dpi=100 myfile.svg
If you don't set the DPI it defaults to 90.
I imagine you can also do this in a Python extension, but I can't help there - but there's probably docs for that.

Related

How to export full glyph as SVG from font?

I used this for FontForge:
fontforge -lang=ff -c 'Open($1); SelectAll(); UnlinkReference(); Export("svg/%n-%e.svg");' font.ttf
This is my original glyph as viewed from within FontForge:
This is what I see in FontForge grid panel (notice it cuts off part of the tail):
And this is what the exported SVG is like from that command, it cuts off the tail as well:
Do I need to modify my font? (I hope not! A lot of work went into making it exactly how it is). Or how can I get it to export the full glyph? Maybe I can tell that command to somehow "add extra x pixels on the top and bottom", so it captures everything?
Also, I don't have to use FontForge commands necessarily for this. If it's possible to export SVGs with proper bounding through some Node.js tool, that works too. Anything to get it to export the full glyph :)
The tail is not cut off. The tail is still there in the file, if you view it in Inkscape you will see this. The reason this is done is so you can edit the SVG and then re-import and FontForge will get the metrics right, it can't be done another way and roundtrip.
If you want to force the viewbox to be larger, just lower the font's descent in Font Info (be careful not to scale the font, lower the descent only).

Is it possible to make Inkscape autotrace PNG to SVG, but from the command line?

I want to automate "raster to vector" conversions. PNG to SVG. (most Qs here on SO are the other way around)
I have tried the old command line tool autotrace on Linux, but I could not get it to run. I've tried to install a package, and to compile it from the source. Nope.
Then I've realised that Inkscape has "autotrace" now integrated in its codebase. I'd like to convert simple sketches from PNG to SVG.
And I want to do this in a Bash for-loop , with different autotrace settings (number of passes; ignore Speckles with max X pixels width) etc.
I've tried the "action" command-line option
inkscape --without-gui --actions="file-open:my.png"
and this brings up the small "png bitmap image import" dialog, waiting for me to confirm.
Also I've tried the verb command line option
inkscape --with-gui --verb="FileImport:my.png"
and this opens the large "Select file to import" dialog (ignoring my --verb argument)
At this point I gave up.
I want Inkscape to import a PNG picture, autotrace it with some settings, save it as SVG. Perhaps, beofre saving, duplicate the traced layer, lock the imported background layer, rename the layers from path-12345 to "tracesettings-x-y-z" etc.
(my final goal is to permute the tracing settings, to find good ones for my use-case, but that's not the focus of this question)
Inkscape is using potrace and autotrace to trace bitmap images into vector formats such as SVG and PDF.
Let's assume you have an image: foo.png that you want to trace to SVG using potrace:
First, you need to convert your image to a bitmap format (BMP).
Invoke the potrace command
# I am using ImageMagick convert command to convert PNG to BMP
convert foo.png foo.bmp
# Invoke potrace command with SVG backend
potrace -b svg foo.bmp
The result will be: foo.svg.

How to convert/package SVG files into an OTF/TTF font?

I'm thinking about using Droid font to create a Ruby-like font for CJK scripts.
However I'm not sure if I can create a script to convert/package multiple SVG files/glyphs into one font file?
"New" glyphs creation
For information, I want to create new glyphs –for CJK glyhs– as follow:
put a Chinese glyph (e.g. 中) into a SVG file ;
add the prononciation (e.g. zhōng) to this SVG.
Once all new CJK glyphs have been created in SVG, I need to package my font
Data would come from Unihan datadase.
Goal
I want something similar to the image below but placing the pronunciation to another place and having different orientation.
FontForge has a Python interface. http://fontforge.org/python.html
A glyph object has methods like export and importOutlines.
My code is untested but reading the FontForge docs the export should go like this:
import fontforge
f = fontforge.open("SomeChineeseFont.ext")
# Not sure if this is the right way to select all glyphs. But you'll get there.
for i in f.selection.select.all():
f[i].export("%s.svg" %i)
Now after weeks of editing SVG's (automate this too). It's time to import:
import fontforge
f = fontforge.open("SomeChineeseFont.ext") # Use the orginal font as base
for i in f.selection.select.all():
# Delete the original glyph or make sure your SVG
# only contains the contours you want to add.
f.clear()
f[i].importOutlines("%s.svg" %i)
f.save("SomeRubyLikeChineeseFont.ext")
Is this what you where looking for?

Make a new font from another one

I was casting around for a solution for to another question I had ( Stretch text in inkscape, but then wrap it to a path ) and I wondered if it was possible to easily and programmatically make one font from another? As a concrete example, can I take FreeSerif font, double its height, and produce another font, calling it FreeSkinnySerif? (I could then use FreeSkinnySerif in Inkscape and get the effect I'm after.)
FontForge Scripting might work for you, in particular scale. I suggest trying out the command in the GUI first, than create the script.
I don't know about a scripting solution, but have you tried the SVG Font editor that is built in to Inkscape?
Text->SVG Font Editor.
I guess that you could make a python script that used it somehow, but simply using the tool from inkscape would probably bee faster.
Here is a tutorial.

Modifying a SVG path to create word art like effects

I am trying to modify a SVG file which has a path converted from a text. I want to be able to manipulate it to create Word Art like effects (eg: Wedge, Widen, Curved text etc).
I've tried many options like parsing the file and modifying each point, but the results are bizarre and curves go wild. There is no tool/library to do this kinda stuff to an svg file.
In short, I am looking for a tool like ImageMagick but for svg. Please Help!!!
Inkscape can do some of this I think, also see this writeup by Tavmjong Bah. Inkscape uses a library called lib2geom to do these effects, and there seems to be a python wrapper for that library.

Resources