How to convert SVG to BMP? - svg

This question may have been answered in multiple websites. However, I am having issues getting it to work correctly.
My goal is to convert an SVG file to BMP using command line. Below is the content of a simple SVG file. Note the resolution must be 912x1140px. Thus the resulting BMP file must be 912x1140px as defined in the SVG.
<?xml version="1.0" encoding="utf-8" ?>
<svg baseProfile="full" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xlink="http://www.w3.org/1999/xlink" width="912px" height="1140px" preserveAspectRatio="none" viewBox="0,0,9.855,6.1614"><defs />
<rect fill="#FFF" height="100%" width="100%" x="0" y="0" />
<rect x="4" y="2.5" width="1.0" height="1.0" fill="#000" />
</svg>
When I use GIMP using GUI, the resulting BMP file is correct as expected having a size of 912x1140px. The size of the file is ~3.96MB. However I must use the GUI to open my SVG file and manually convert it to BMP. I prefer to use command line because I have a batch of SVG files I want to convert.
When I use ImageMagick to convert, the resulting BMP file gets resized to 855x1069px instead of staying at 912x1140px. The resulting BMP file ~3.48MB: convert myfile.svg myfile.bmp
When I use rsvg-convert, the resulting BMP file is correct 912x1140 but its around 7KB. I am unsure if rsvg-convert even supports BMP format because according to the docs, BMP is not listed as the support format. Thus this leads me to question if the convert BMP file is even correct. rsvg-convert -o myfile.bmp myfile.svg
When I use command line Inkscape, the resulting BMP file is correct resolution of 912x1140, but size is around 6.51KB. I am unsure if this is correct since the BMP file generated using GIMP results in a file size of 3.96MB. Secondly, Inkscape GUI doens't have any options to export to BMP. In addition, it defaults to 32 bits. I want it to be 24 bit depth. inkscape -z myfile.svg -e myfile.bmp

Related

How to convert SVGs to GIFs with ImageMagick?

I'd like to convert a SVG that has a reference to a GIF inside into a final GIF.
The SVG shows fine with the GIF in a browser, but converting the file from SVG to GIF results in only converting the first frame of the GIF.
that's my test.svg:
<svg id="TEST" data-name="TEST" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="1000" height="1000" viewBox="0 0 2000 2000">
<image width="2000" height="2000" xlink:href="input.gif"/>
</svg>
imagemagick command:
magick convert test.svg output.gif
the result is that only the first frame gets converted into a GIF, not the whole sequence.
Anything I can adjust with the ImageMagick command to make this work?

svg + inkscape + unwanted cropping

Given the following test.svg file
<?xml version="1.0" encoding="utf-8" ?>
<svg baseProfile="tiny"
height="5cm" version="1.2"
viewBox="-1 -1 2 2"
width="5cm" xmlns="http://www.w3.org/2000/svg"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xlink="http://www.w3.org/1999/xlink">
<defs />
<rect fill="blue" height="1" width="1" x="0" y="0" />
</svg>
using the command
inkscape -D -z --file=test.svg --export-pdf=text.pdf --export-latex
I get a pdf of 25mm x 25mm. The proportions are correct (I use only half the width and half the height), my question is how do avoid an automatic crop of the picture. I need a PDF of 50mm x 50mm, with only the left upper square filled.
In the inkscape documentation for the option -D (that I use) there is the comment without margins or cropping that is exactly what I need. The result is as described above, cropped.
man inkscape shows the following explanation for -D:
In SVG, PNG, PDF, PS, and EPS export, exported area is the drawing (not page), i.e. the bounding box of all objects of the document...
That is what you describe as cropping. For -C it says:
In SVG, PNG, PDF, PS, and EPS export, exported area is the page. This is the default for SVG, PNG, PDF, and PS, so you don't need to specify this...
So, simply leave off the -D option.

How Do I export an SVG without it getting an <image> element and not a <path>

I keep exporting a PSD element with a clear background as an SVG and I continue to get
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="0.972in" height="0.861in">
<image x="0px" y="0px" width="70px" height="62px" xlink:href="data:img/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEYAAAA+CAMAAAChgZ0aAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAACfFBMVEUnKzT///8nKzQnKzQnKzQnKzQnKzQnKzQnKzQnKzQnKzQnKzQnKzQnKzQnKzQnKzQnKzQnKzQnKzQnKzQnKzQnKzQnKzQnKzQnKzQnKzQnKzQnKzQnKzQnKz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U/VEgVHKcaAhczio8duKU/IIwdWgCwGssjDpj11Q6kg29rzGbjBCAPJnstuzgXlqL9on6jSGNp9+LKVSesvg8iI54AnDJiSsGaA5MJ4Rf+x0jFZy2HgtQHrHn4jEiy2Y8xbp6AsBk5fpWPZApdwCM3Pd43gJQZq39Oh44NTMJMOd4la8BoD1o/U/E9V7aFs8tnru4MPGIDFxPm8uu29iIbogdjeucdAxjv8XR/hgPuFqJES/tkDBlrT7QNmiZQYIi8xkEqHuthsaPhK5+BvoAgDZhow/Xc6VRpkvJRnDFib7GfuHz9BMQYgX6D8+g1qMFBEA/ZH3oB7h4G/98P/DXKj2zD/AZ/Mbsp7NMuGAAAAAElFTkSuQmCC" />
</svg>
I would like to export this as a <path> element instead of <image>
this is the PNG of what that SVG is:
I have converted already tried to image trace this on illustrator but the path gets sloppy.
Thanks,
Zlerp
Sorry but Photoshop just doesn't do SVGs like that. SVG is a vector format and the only things in photoshop that are vectors are paths and selections and neither of those have things like line thickness and color so they'd be invisible as an image.
That's what Illustrator is for. Or for a free option, there's InkScape.

ImageMagick viewbox when converting SVG

I'm trying to convert an SVG file to a PNG using convert, where the input image has SVG artifacts outside the document border - this is a byproduct of sloppy artistry, and is convenient when drawing a pretty picture.
However, when I try to use ImageMagick to convert the SVG file to a rasterized PNG, convert keeps the artifacts outside the border in the result, and recalculates the SVG viewbox. This looks very ugly, and is not what I would like as a result. For instance, I would run the following command:
convert input.svg -depth 200 -units pixelsperinch -border 11inx17in output.png
The SVG document clearly has the border and viewbox defined:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
version="1.1"
id="svg2"
viewBox="0 0 990.00002 1530"
height="17in"
width="11in">
...
Yet convert treats the entire SVG document (artifacts and all) as the input image, recalculates the viewbox, and the resulting output is slightly skewed, in addition to the extra artifacts spilling outside the document border.

How can I make text automatically scale down in an SVG?

I've got an SVG element that I've created with Inkscape. I then take that SVG and put in as part of an XSL-FO stylesheet that is used to transform XML data and then passed through the IBEX renderer to create a pdf (which is usually then printed). As an example, I have elements in the svg/stylesheet that look like this (extra noise due to the Inkscape export):
<text x="114" x="278.36218" id="id1" xml:space="preserve" style="big-long-style-string-from-inkscape">
<tspan x="114" y="278.36218" id="id2" style="style-string">
<xsl:value-of select="Alias1"/>
</tspan>
</text>
My problem lies in the fact that I don't know how big this text area is going to be. For this particular one, I've got an image to the right of the text in the SVG. However, if this string is the maximum allowed number of W's, it's way too long and goes over the image. What I'd like (in a perfect world) is a way to tell it how many pixels wide I want the text block to be and then have it automatically make the text smaller until it fits in that area. If I can't do that, truncating the text would also work. As a last ditch resort, I'm going to use a fixed width font and do the string truncation myself in the XML generation, although that creates something both less usable and less pretty.
I've poked around the SVG documentation and looked into flowRegions a bit as well as paths, but neither seem to be be quite what I want (maybe they are though). If it helps, here's that style string that Inkscape generates:
"font-size:20px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
Thanks in advance for the help.
You have text of arbitrary line length (in terms of characters) and you want to scale it to fit inside a fixed amount of space? The only way I can think of to rescale text to a fixed size is to place it inside an svg element and then scale the SVG to that size:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="100%" height="100%" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>Resizing Text</title>
<defs>
<svg id="text-1" viewBox="0 0 350 20">
<text id="text-2" x="0" y="0" fill="#000" alignment-baseline="before-edge">It's the end of the world as we know it, and I feel fine!</text>
</svg>
</defs>
<rect x="500" y="100" width="200" height="40" fill="#eee" />
<use x="510" y="110" width="180" height="20" xlink:href="#text-1" />
</svg>
However, as seen above, the viewBox on the encapsulating svg element needs to be set to the width of the text, which you presumably don't know.
If you're referencing this SVG inside a user agent with scripting available (e.g. a web browser) then you could easily write a script to capture the width of the text or tspan element and set the viewBox accordingly.

Resources