Resize of svg icons from command line

This post would probably only useful to me, but, it is possible to change the size of svg files using XSLT (why would one need to change size of vector graphics??? Well, there are cases where there are no means to scale the images)

I had a bunch of files which I needed to resize into a proper size (in my case, 16px x 16px icons), and was looking for a easy solution. Since I knew svg is xml-based vector graphics, I was hoping to find example similar to

I used the xsl file from the post on https://www.ruby-forum.com/topic/166757#732031, with adding the 16x16px as a target scale.
Command line to run:
xsltproc --stringparam scale 2.5 bigger.xsl in.svg >out.svg
<?xml version="1.0"?>
<!-- bigger.xsl $Id$
     Author: Terry Brown
     Created: Thu Sep 25 2008
-->
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:svg="http://www.w3.org/2000/svg"
  xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
  >
  <xsl:output method="xml"/>
  <xsl:template match="svg:svg">
    <xsl:copy>  <!-- copying the svg element -->
      <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>

Thanks Terry Brown!  

Comments

Popular posts from this blog

Timeline on Latex

Exporting Skype Chat/Skype Contacts to csv file using the shell script and sqlite3 (usually already installed on mac)

trim() not supported by IE7 and IE8