Skip to content

Instantly share code, notes, and snippets.

@dpineiden
Created February 12, 2019 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dpineiden/d427d74fd6c2b827e9a7c42b8dc56a28 to your computer and use it in GitHub Desktop.
Save dpineiden/d427d74fd6c2b827e9a7c42b8dc56a28 to your computer and use it in GitHub Desktop.
Inkscape fit to draw all images
#!/bin/bash
# inkscape-center <file-or-directory>...
# https://graphicdesign.stackexchange.com/questions/22326/how-to-fit-svg-drawings-to-their-canvas-on-the-command-line
_analyse() {
if [ -d "${1}" ] ; then
_centerAll "${1}" ;
else
_center "${1}" ;
fi
}
_centerAll() {
cd "${1}" ;
for img in $(ls "*.svg") ; do
_filterSyms "${img}" ;
done
}
_filterSyms() {
if [[ $(readlink "${1}") == "" ]] ; then
_center "${1}"
fi
}
_center() {
inkscape --verb=EditSelectAll --verb=AlignHorizontalCenter --verb=AlignVerticalCenter --verb=FileSave --verb=FileQuit "${1}"
}
for arg ; do
_analyse "${arg}" ;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment