svg-resizer
is a command line interface Javascript utility useful for single or batch
resizing SVG files (with '.svg' file extensions). It's great for OSX, and I am attempting
to use it in my latest shell scripts. Below I provide notes on the series of steps that I
used to install svg-resizer
and get it working on my macOS Sierra machine, on date
February 20, 2017.
librsvg2
is a key dependency of svg-resizer
. So, I checked if this library was
already on my machine by seeing whether a list check returned 0 (=absent) or 1 (=present):
$ brew list | grep "librsvg" | wc -l
Brew list check returned 0, so I installed librsvg2
using $ brew install librsvg
.
You could also automate this in a script using a clean little if-else-fi, as follows:
$ BREW_CHECK="$(brew list | grep "librsvg" | wc -l)"
$ if [ $BREW_CHECK = "0" ]; then
$ echo "You need librsvg2, the main dependency of svg-resizer."
$ brew install librsvg
$ else
$ echo "librsvg2 is already installed on your local machine."
$ fi
Downloaded as zip from https://github.com/vieron/svg-resizer, and then placed in ~/scripts folder on my local machine. No other installation procedures are required.
Downloaded lastest version dmg installer (https://nodejs.org/dist/v7.5.0/node-v7.5.0.pkg) of Node.js from website (https://nodejs.org/). Simply get this, go through install steps (e.g. agree to license), and finish the install.
I opened bash profile file ($ nano ~/.bash_profile
) and added the lines below to it,
then sourced bash profile to save settings ($ source ~/.bash_profile
).
# Added after installing Node.js Feb 2017
export NODE_PATH=$NODE_PATH:/usr/local/lib/node_modules
Here, npm
is the Node.js Package Manager, a command line software management utility
responsible for installing packages and updating packages and dependencies. npm
comes
bundled with the Node.js distro. I updated several Node.js modules in order to meet
prerequisites for running svg-resizer
, using the following code (note use of super
user do, 'sudo', meaning you have to have root/admin access to replicate this):
$ sudo npm install shelljs -g
$ sudo npm install fs-extra -g
$ sudo npm install lodash -g
$ sudo npm install nomnom -g
Finally, I used svg-resizer
with the following code to successfully (and nicely!)
reduce the size of one of my .svg files. The path to the .svg file is the (only) required
positional parameter/input, the x and y flags specify the final width and height of the
output image, and the .
specifies for the modified file to be placed in my current
working directory.
$ cd /Users/justinbagley/scripts/svg-resizer-master
$ node ./svg-resizer.js -f -x 400 -y 300 -o . \
../DISTRUCT_plots/3hfiles_x2_vertical.svg
I used the following code to do the conversion to PDF, and the WARNING message had no effect on the outcome, hence can be ignored.
$ inkscape -z -A 3hfiles_x2_vertical.pdf ./3hfiles_x2_vertical.svg
2017-02-20 14:32:16.559 inkscape[6277:12242726] *** WARNING: Method
userSpaceScaleFactor in class NSView is deprecated on 10.7 and later. It
should not be used in new applications. Use convertRectToBacking: instead.