Last active
April 1, 2021 02:25
-
-
Save dreness/1ebb2a9b3175ccdaa1fd109f84e30243 to your computer and use it in GitHub Desktop.
Batch convert SVGs to PDF using Inkscape
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
IMAGE_DIR=$1 | |
INK="/Applications/Inkscape.app/Contents/MacOS/inkscape" | |
SCRIPT="inkscript" | |
COUNT=0 | |
# If gdate is available (brew install coreutils), we can show precise timing info | |
type -a gdate &> /dev/null && HAS_GDATE=1 | |
# Make a script for Inkscape's --shell mode | |
makeInkScript() { | |
for file in *.svg ; do | |
echo << EOF >> ${SCRIPT} | |
file-open:${file} | |
export-filename:${file}.pdf | |
export-type:pdf | |
export-do | |
file-close:${file} | |
EOF | |
COUNT=$((COUNT += 1)) | |
done | |
echo "Batching ${COUNT} images..." | |
} | |
doAllThatStuff() { | |
cat ${SCRIPT} | ${INK} --shell &> /dev/null | |
} | |
pushd $IMAGE_DIR | |
[ ! -z $HAS_GDATE ] && INK_START=$(gdate +%s.%N) | |
makeInkScript | |
[ ! -z $HAS_GDATE ] && INK_END=$(gdate +%s.%N) | |
if [ ! -z $HAS_GDATE ] ; then | |
echo -n "Time required to compose Inkscape script: " | |
echo $((INK_END - INK_START)) | |
fi | |
[ ! -z $HAS_GDATE ] && CONVERT_START=$(gdate +%s.%N) | |
doAllThatStuff > /dev/null | |
[ ! -z $HAS_GDATE ] && CONVERT_END=$(gdate +%s.%N) | |
if [ ! -z $HAS_GDATE ] ; then | |
echo -n "Time required to convert images: " | |
echo $((CONVERT_END - CONVERT_START)) | |
fi | |
popd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍🏻