Skip to content

Instantly share code, notes, and snippets.

@osuka
Created June 17, 2012 22:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save osuka/2945864 to your computer and use it in GitHub Desktop.
Save osuka/2945864 to your computer and use it in GitHub Desktop.
Create hi-res versions of images with Inkscape and Crop them with Gimp
#!/bin/bash
howmany=`ls *.svg|wc -l`
if [ $howmany -eq 0 ] ; then
echo "Please launch this from inside a folder with svg files."
exit
fi
# In Mac OS X scripting only works when invoked with FULL PATH
INKSCAPE="/Applications/Inkscape.app/Contents/Resources/bin/inkscape"
GIMP="/Applications/Gimp.app/Contents/Resources/bin/gimp"
if [ ! -x ${INKSCAPE} ] ; then
echo "This script needs Inkscape, please download it from http://www.inkscape.org"
exit 1;
fi
if [ ! -x ${GIMP} ] ; then
echo "This script needs Gimp, please download it from http://www.gimp.org"
exit 1;
fi
mkdir -p png
for svgname in *.svg; do
lopngname="$(pwd)/png/${svgname%.svg}_lo.png"
hipngname="$(pwd)/png/${svgname%.svg}_hi.png"
echo "----------------------- ${svgname}: Creating PNG"
${INKSCAPE} --without-gui --export-background=0 --export-background-opacity=255 --export-area-page --export-png="${lopngname}" --export-dpi=90 "${svgname}"
${INKSCAPE} --without-gui --export-background=0 --export-background-opacity=255 --export-area-page --export-png="${hipngname}" --export-dpi=180 "${svgname}"
echo "------------------------ ${lopngname}: Cropping"
${GIMP} -i -b "(let* ( (filename \"${lopngname}\") (image (car (gimp-file-load RUN-NONINTERACTIVE filename filename))) (drawable (car (gimp-image-get-active-layer image)))) (plug-in-autocrop RUN-NONINTERACTIVE image drawable) (file-png-save RUN-NONINTERACTIVE image drawable filename filename 0 8 0 0 0 1 1) (gimp-image-delete image)) (gimp-quit 0)"
${GIMP} -i -b "(let* ( (filename \"${hipngname}\") (image (car (gimp-file-load RUN-NONINTERACTIVE filename filename))) (drawable (car (gimp-image-get-active-layer image)))) (plug-in-autocrop RUN-NONINTERACTIVE image drawable) (file-png-save RUN-NONINTERACTIVE image drawable filename filename 0 8 0 0 0 1 1) (gimp-image-delete image)) (gimp-quit 0)"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment