Newbie here. Thanks for allowing me to join the forum. And thinks for providing such excellent software.
I have used Inkscape to produce images of the size I need for importing into LibreOffice-Writer documents. I would like to be able to use the Inkscape command line to change the size of some of these .svg files, preferably by simply providing input and output file names and a single scale factor. I've looked through the man pages, but nothing seems to obviously match. Perhaps I don't understand Inkscape's geometry well enough.
Does Inkscape provide this feature? If not, is it possible to accomplish the same result by providing more input than just a single scale factor? If no to both of these, do you have any suggestions, other than manually opening each file? Also, if you don't have this feature, is it something we might look forward to in the future?
Incidentally, I was happy to see that LO writer 6.0.7.3 would import Inkscape's .svg files, both embedded and linked, behaving properly when the linked source files were updated externally in Inkscape. That is really cool. I don't think LO writer used to do this.
OTOH, if you want scaled SVG output, it should be fairly easy to use a tiny XSLT program to just modify the outer 'viewBox' attribute. xsltproc is a portable and widely available XSLT processor. You would end up running a command like:
Thanks for the help, folks. To answer ronburk's question, I want to produce an svg image, rather than bitmap. It looks like I need to become familiar with xslt programming and with the structure of svg files. Maren, thanks for the comment about doing the scaling within LO. I'm anticipating a relatively large number of images, and I'd like to standardize and automate the workflow as much as possible. So I'd like to do the image manapulation outside of LO, as much as possible. If that turns out not to be feasible, then yes, I'll follow your suggestion.
Yeah, you really want to cookbook this if you can. XSLT is the best language in the world to avoid learning if at all possible. Here's a program that may do all you need:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" xmlns:str="http://exslt.org/strings" extension-element-prefixes="str exsl" version="1.0" > <!-- scale defaults to "1.0", no change in scale --> <xsl:param name="scale">1.0</xsl:param>
Ronburk, thanks very much for the program. I hadn't visited this forum for several days, so today was the first I saw it. I'll try this out in the next few days and let you know how it worked. Thanks again.
Ron, I apparently don't have xsltproc on my (linux) system. I read through your code and compared it to what I saw looking at an svg file in the text editor. It seems to change the last 2 parameters of viewBox. I tried doing this manually in the editor, and it did reduce the size of the image in inkscape and also when imported. Problem is that both in inkscape and after import the image is the right size, but the bounding frame is too large.
When I manually changed values of height and width (just before viewbox) it did exactly what was needed, far as I can tell. So I'll try to put this into a bash script and see how it works. If there are any particular warnings about hammering on an svg file this way, please let me know.
I wouldn't be afraid to use any old language to do this -- so long as I'm not turning it over to someone else who's going to call me if it stops working. I don't like to get those phone calls, so in that case I would use something that actually parses the XML (as XSLT does implicitly) so that completely trivial changes in .svg formatting by Inkscape would not break the code.
Most likely the default package manager of your favorite Linux dist can find/install xsltproc for you; your dist probably already has the libraries that xsltproc thinly wraps around, since they are in widespread use across Linux-land.
Newbie here. Thanks for allowing me to join the forum. And thinks for providing such excellent software.
I have used Inkscape to produce images of the size I need for importing into LibreOffice-Writer documents. I would like to be able to use the Inkscape command line to change the size of some of these .svg files, preferably by simply providing input and output file names and a single scale factor. I've looked through the man pages, but nothing seems to obviously match. Perhaps I don't understand Inkscape's geometry well enough.
Does Inkscape provide this feature? If not, is it possible to accomplish the same result by providing more input than just a single scale factor? If no to both of these, do you have any suggestions, other than manually opening each file? Also, if you don't have this feature, is it something we might look forward to in the future?
Incidentally, I was happy to see that LO writer 6.0.7.3 would import Inkscape's .svg files, both embedded and linked, behaving properly when the linked source files were updated externally in Inkscape. That is really cool. I don't think LO writer used to do this.
Thanks for your help.
If many files are using the same size SVG, one option is to use a text editor to change the height and width in all documents via find & replace.
To be clear: do you want to produce an svg file or a bitmap?
I didn't immediately see any way to do it for svg output, but OTOH I couldn't even really get the --verb option to do anything at all.
I think there is no way to do that in Inkscape. However, you can scale the images losslessly in LibreOffice.
OTOH, if you want scaled SVG output, it should be fairly easy to use a tiny XSLT program to just modify the outer 'viewBox' attribute. xsltproc is a portable and widely available XSLT processor. You would end up running a command like:
xsltproc --param scale .5 scaler.xslt input.svg >output.svg
Thanks for the help, folks. To answer ronburk's question, I want to produce an svg image, rather than bitmap. It looks like I need to become familiar with xslt programming and with the structure of svg files. Maren, thanks for the comment about doing the scaling within LO. I'm anticipating a relatively large number of images, and I'd like to standardize and automate the workflow as much as possible. So I'd like to do the image manapulation outside of LO, as much as possible. If that turns out not to be feasible, then yes, I'll follow your suggestion.
Thanks again for the help.
Yeah, you really want to cookbook this if you can. XSLT is the best language in the world to avoid learning if at all possible. Here's a program that may do all you need:
<?xml version="1.0"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exsl="http://exslt.org/common"
xmlns:str="http://exslt.org/strings"
extension-element-prefixes="str exsl"
version="1.0"
>
<!-- scale defaults to "1.0", no change in scale -->
<xsl:param name="scale">1.0</xsl:param>
<!-- copy input to output -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!-- Except for this one attribute -->
<xsl:template match="@viewBox[local-name(..)='svg']">
<xsl:variable name="inputBox" select="str:tokenize(.)"/>
<xsl:attribute name="viewBox">
<xsl:value-of select="concat($inputBox[1],' ',$inputBox[2], ' ',$inputBox[3] * $scale,' ',$inputBox[4] * $scale)"/>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
You run that like this:
xsltproc --param scale 2 scale.xslt input.svg >output.svg
The 'scale' parameter divides the width and height of the viewbox, so a value of "2" means to scale to 1/2 the size.
YMMV, backup your files, don't trust code you got off the internet, etc.
Ronburk, thanks very much for the program. I hadn't visited this forum for several days, so today was the first I saw it. I'll try this out in the next few days and let you know how it worked. Thanks again.
Ron, I apparently don't have xsltproc on my (linux) system. I read through your code and compared it to what I saw looking at an svg file in the text editor. It seems to change the last 2 parameters of viewBox. I tried doing this manually in the editor, and it did reduce the size of the image in inkscape and also when imported. Problem is that both in inkscape and after import the image is the right size, but the bounding frame is too large.
When I manually changed values of height and width (just before viewbox) it did exactly what was needed, far as I can tell. So I'll try to put this into a bash script and see how it works. If there are any particular warnings about hammering on an svg file this way, please let me know.
Thanks again for the help.
I wouldn't be afraid to use any old language to do this -- so long as I'm not turning it over to someone else who's going to call me if it stops working. I don't like to get those phone calls, so in that case I would use something that actually parses the XML (as XSLT does implicitly) so that completely trivial changes in .svg formatting by Inkscape would not break the code.
Most likely the default package manager of your favorite Linux dist can find/install xsltproc for you; your dist probably already has the libraries that xsltproc thinly wraps around, since they are in widespread use across Linux-land.