inkscape command line svg to png - set both width and dpi - svg

I want to convert a svg to a png with the inkscape command line tool. Despite of what is specified in the svg i want to set both the width of the resulting png and the dpi to be used. From the inkscape docu it seems this is not possible:
-w WIDTH, --export-width=WIDTH
The width of generated bitmap in pixels. This value overrides the --export-dpi setting (or the DPI hint if used with --export-use-hints).
I can't really understand how this could be as the width and the dpi used should not be directly related. How can I achieve to set both values.
Thanks, Martin

Ok got it I think, here as it goes in my concrete example:
In the svg the width is 2480 pixel (what you need for DinA4 300 dpi print). Now my mistake was to add "-d 300" to the inkscape call which doesn't make sense if the svg does not give the width in some unit. When doing so the resultant image has a width of 2480 * 300 / 90 = 8267 pixel . So if working with pixel in the svg you need to be aware of the fact the inkscape interprets this as 90 dpi ...
Well i guess only my confusion here yet happy to share ;-)

Related

How to create SVG from PNG

I've been using inkscape to create SVGs. But I've come across a problem. I've created a simple plus sign with a 1px line width (as simple as you can imagine). It is currently in PNG format with a transparent background. I've imported it into inkscape so I can convert it into a SVG. However, when I use trace bitmap, Inkscape CHANGES THE SHAPE such that the straight lines that are one pixel wide are tappered with pointed ends! I've tried different options in the trace bitmap settings but nothing seems to work. I've also gone through a number of online free conversion sites with no luck.
I wouldn't mind just creating the plus sign using html and css but the exact position of the lines as well as the line thickness tends to move around between chrome and firefox. It's very strange.
..Help?
I think I figured it out. If I create a plus sign that is 2 px thick instead of 1 px thick, inkscape does not do its smoothing thing (as long as I have unticked smoothing options). So, I do this, but draw it much bigger than what I need. Then when I load it into my website I can reduce the size of it there, and voila the 2 px width becomes 1 px width!

How to rasterize svg to png without aliasing effect with "data:image/svg+xml" with Inkscape?

I have a problem while export svg to png with svg which includes some element image objects using Inkscape.
Example:
<image xlink:href="data:image/svg+xml;base64,PD94bWwgdm....Zz4=" x="-312" y="-139" width="624" height="278"></image>
Notes:
- When I open svg in web browsers, when zoom in browser images are nice, and not have aliasing effect.
- But using Inkscape command : /Applications/Inkscape.app/Contents/Resources/bin/inkscape /test/test.svg -e /test/test.png -d 300 --> image is aliasing.
Here is result on browser and output png file:
Here is my files:
1. https://drive.google.com/open?id=1Wjt-QnX4iPL3QYHfYLI7wVfq26yBCe3e --> svg file which include with svg data "data:image/svg+xml"
2. Exported png using inkscape with dpi 300
https://drive.google.com/open?id=1k171_ARwnw0-5iyM7vwJsH_h6tFWpb1v
Please help me!
Thank you!
Use a raster file that uses the correct export dpi
Scale it to the correct size in Inkscape
Position it at a full pixel value
(untested, but should work)
In (future) Inkscape 1.0, you can also uncheck the antialiasing functionality in the export dialog, but not sure how that affects raster images. It might not look good.

How can I convert the SVG to a PNG without jagged lines?

When you look at the rendered version of the SVG https://commons.wikimedia.org/wiki/File:Triangle-perpendicular.svg, it has jagged lines:
For example, the line AC doesn't look as it should look. How can I convert this image to a PNG without getting jagged lines?
What I've tried
inkscape +antialias -background none -z -e test.png -w 276 Triangle-perpendicular.svg
This seems not to have any effect.
I've been looking at the original source svg, and it doesn't render terribly well in the browser either. AFAICT, you are rendering with antialiasing, but the stroke width and angle of your triangle are conspiring to look awkward. Try increasing the stroke width a little, or (if you can), change the angle of the line. Both might help.
The original stroke width is .79..., try 1.0

Scale svg figure in html output of Sphinx (rest)

I have a figure in restructured text using a scale directive as follows:
.. figure:: images/my_image.svg
:scale: 150 %
The the image is perfectly OK in the HTML output of sphinx, except that it is not scaled. (The svg image has width and height information and a viewBox)
It is strange, that in contrast to png figures, the <img> tag in the HTML file does not contain width and height attributes of the image (hm, can't sphinx determine width and height of the svg for some reason?).
What is the reason for this? Does sphinx support the :scale: directive for svg figures?
You may try setting the width. This can also be assigned a percentage of the current line width as value.
.. figure:: images/my_image.svg
:width: 100%

scaling svg figure

I tried to resize svg file to be opened in illustrator with smaller width and height(pixels or cm), I did this by changing width, height and viewBox attributes in <svg> tag, but it doesn't work at all. By search I have found that transform attribute via matrix value affects the real resizing of the figure, any ideas about ready made functions or scripts using python or librsvg to successfully scaling the svg figure, by the way I'm using inkscape to produce svg files. THANKS
You could try svg scour, that should be able to find a good viewBox to use (note spellning and uppercase 'B'). Then change only the width and height attributes to be whatever you want, and hopefully that should work.

Resources