ImageMagick convert SVG with text and external fonts to SVG with shapes (outlines) with no external fonts - svg

I'm looking to to use ImageMagick to convert an SVG file with text and external fonts to another svg without text, instead have them be shapes or outlines.
Basically, can ImageMagick do the equivalent of Illustrator's "Create Outlines" functions?
I can currently convert the svg to png and all the text and fonts render correctly, but I'm just looking to remove need for the person opening the svg to have the correct fonts installed on their computer.

I believe that your installation of ImageMagick needs to be configured with the the "--with-autotrace" switch and Autotrace needs to be installed. Then a simple conversion command should work:
convert text.png vector.svg

I doubt ImageMagick will do it. What you need to do is load the SVG into an editor like Inkscape. Select the text and then convert it using Path->Object to Path.
Then you can save it and you can distribute it without worrying about the user not having the fonts.

Related

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.

Why doesn't librsvg doesn't export the black paths in a PNG?

Here is an SVG image I want to convert to PNG with librsvg in my program.
This is a PNG version of the SVG exported from Inkscape:
This is a bitmap of the same SVG exported with librsvg:
Only the white portions of the image are exported. The black portions, despite being well-defined in the background, appear transparent.
This problem occurs whether I use the librsvg API or the program rsvg-convert. You can use the W3 validator to see that the SVG's markup is valid.
I notice the same thing happens in the thumbnails of the SVGs in my file browser. Perhaps they're using librsvg?
Upon digging into the files I discovered that, for some reason, the fill of the black portion was set to "fill:currentColor". I don't know where that came from, but changing it to "fill:#000000" fixed the problem.

SVG file looks different in webbrowser than in Illustrator

I've been doing some stuff in Illustrator and I have a problem with saving a project in to SVG file that I open in webbrowser, It just looks different.
And it hapens only in SVG, if I save it to PDF or PNG it looks how it should.
What am I doing wrong?
That's how it looks in Ai
That's how it looks in webbrowser
Here's a link to download rar file with .ai and .svg that I have.
Since all browsers render it the same way, it would seem likely that this is a bug in the AI SVG export filter.
To me it looks like you are applying a blend mode ("Overlay" perhaps?) to the white parts on top of the image. That effect ought to be reproducible using SVG filters, but perhaps AI's exporter doesn't support that yet.
If you are using an "odd" blend mode, try changing it, or reproducing the effect another way.
Individual pixel control needed in identical svg conversion is not possible. SVG creates only specific shapes. The Ai app conversion seems to use opacity to provide the color shades. You could probably tweek opacity and add some svg filters to improve the svg.
Print your design in a . pdf file instead of exporting it directly. Then open the printed .pdf back in Illustrator and export the .svg from this one, it shoud do the trick.

How to force conversion of glyphs to embedded vector paths in Inkscape

I have created an SVG document with Inkscape. It contains text in a non-standard font. The svg xml references the font. So, the vector has a dependency on the font being available on the users machine (or by using web fonts in a web scenario). I want to remove this dependency. I know how to do it manually, but it would be time consuming.
Does Inkscape provide a way to include the required glyphs as pure vectors instead of referencing the font?
You can transform all glyphs to vectors by selecting them and using the object to path function (Path->Object to Path).
Select the text(s) you want to convert to paths, then select "Path > Object to Path".
If the font license allows it you could also use it as a webfont, by adding some css to the svg file, see this example. Inkscape doesn't support webfonts AFAIK, but for editing I guess it might still work if you have the same font installed on your system.

ImageMagick convert SVG to PNG not working with RSVG enabled

I'm using ImageMagick's convert utility to convert SVG file to PNG image. At first, I used vanilla installation of IM on OSX (brew install imagemagick) to convert the SVG using:
$ convert file.svg file.png
This worked except that some of the image objects in that file were offset (actual links to images). I then read a related question that suggested ImageMagick to be compiled with rsvg support (homebrew does it with brew install imagemagick --use-rsvg).
Now, when I try to perform the conversion, no images are rendered. I tried using this SVG file, and the resulting PNG was blank. However, if any text exists on the SVG, it's rendered in the proper location. Any ideas how to proceed? thanks.
You should run this command to see a list of all 'delegates' your ImageMagick is trying to use:
convert -list delegate
To discover which delegate command ImageMagick uses for SVG processing, run
convert -list delegate | grep 'svg ='
You should see the binary + commandline parameters your convert tries to use. Im my case it is /opt/local/bin/rsvg-convert (but I'm not using Homebrew, I use MacPorts).
Now check if the binary is present at all on your system:
If yes, run it directly and debug from there.
If no, try to find where your Homebrew installation installed it, and change ImageMagick's configuration file for its delegates. It's called delegates.xml. MacPorts places it into /opt/local/etc/ImageMagick/delegates.xml -- I don't know where Homebrew stores it.
However, since your un-modified installation was already working, there must have been an SVG consuming delegate at work already then. Otherwise you would not have gotten any SVG processed at all.
This internal SVG rendering method of ImageMagick is called MSVG. This is far from being a feature-complete SVG interpreter/renderer.
Update:
To see what ImageMagick is doing for which format, run this command:
convert -list format
and for SVG run
convert -list format | grep SVG
Output on my system is:
MSVG SVG rw+ ImageMagick's own SVG internal renderer
SVG SVG rw+ Scalable Vector Graphics (RSVG 2.36.1)
SVGZ SVG rw+ Compressed Scalable Vector Graphics (RSVG 2.36.1)
After you installed rsvg, the internal method to render SVGs will not have gone away. You can still force ImageMagick to use the internal renderer by adding MSVG: to the commandline like this:
convert MSVG:file.svg file.png
Just for completeness' sake...
Oh, I now had a look at the SVG file you linked to.
It contains JavaScript. I do not think that the RSVGlib does support JavaScript inside SVGs. I know for sure that the internal SVG coder named MSVG does not.
I had a similar problem and was just told to install inkscape and it works,
ImageMagick converts svg graph into pdf with tilted x-axis labels, any ideas?
The delegate list did not change but the output did. On further fiddling with forced MSVG I could not get the problem to go away. So another delegate is probably the best solution.

Resources