I have some images that I made in inkscape with
.svg extension. These images are various size (256*265, 512*512, etc) in pixels.
How can I change the size of all these images at once in Linux?
Without knowing your reasoning for wanting to do this, my initial reaction is don't do it.
The size of an SVG file is really a suggestion—they are designed to be scaled up and down in size (hence scalable vector graphics). The height and width of an SVG file for most practical uses does not matter. If you want the image to be bigger on (for example) a web page, you can just set the height and width attributes. If you are exporting to a PNG file, you can set the dimensions to anything you want. The
width attributes are, in fact, not even required to be there. If height or width isn't specified on the root
<svg> element, it'll just default to 100%.
Fiddling around with height and width really misses one of the great benefits of SVG files, which is scalability.
There may be instances where you really do need to set the height and width of an SVG file, but this will usually be because of a limitation in your workflow or tools in my opinion.
SVG files are just XML files—you can open one up in a text editor and take a look. You can manipulate them just like you would any other XML file. Mozilla Dev Network has a fantastic reference for learning about the XML side of SVG files.
To manipulate an XML file, the traditional method is to use XSL, a stylesheet language for transforming one XML file into something else (usually another XML file).
Create a text file named scale-svg.xsl and insert the following content:
<xsl:stylesheet version="1.0"> <xsl:output method="xml"/> <xsl:template match="svg:svg"> <xsl:copy> <xsl:copy-of select="svg:metadata|svg:defs|sodipodi:namedview"/> <xsl:element name="svg:g"> <xsl:attribute name="transform"> <xsl:value-of select="concat(concat('scale(',$scale),')')"/> </xsl:attribute> <xsl:copy-of select="*[not(svg:metadata|svg:defs|sodipodi:namedview)]"/> </xsl:element> </xsl:copy> </xsl:template> </xsl:stylesheet>
Now you need to apply the stylesheet to an SVG file (or files). There are lots of XSLT programs available. If you are using Linux,
xlstproc is probably already installed.
# This command will scale small.svg up by 3x $ xsltproc --stringparam scale 3 scale-svg.xsl small.svg>big.svg # This command will scale all SVG files in the current directory $ for f in *.svg; do xsltproc --stringparam scale 3 scale-svg.xsl $f>3x_$f; done
If you want to do something different (such as manipulate the height and width of the SVG document rather than scale it), you'll need to modify the XSL file to meet your needs. There are a lot of tutorials out there about XSL, such as this one at W3Schools.
While Inkscape does have batch processing abilities, I don't believe it can do this (again, the dimensions of an SVG file are suggestions, so the usefulness is limited).
Inkscape does have the ability to automate exporting SVG files at different sizes. The Inkscape command line options have the ability to manually set the height and width when exporting a PNG file.
I found the solution to my problem, the way to do this is by using
and after searching in 3W i found this script here
all you need is make this script executable and run it followed by new size for your