Skip to content

Instantly share code, notes, and snippets.

@geta6
Created February 23, 2012 01:05
Show Gist options
  • Save geta6/1888914 to your computer and use it in GitHub Desktop.
Save geta6/1888914 to your computer and use it in GitHub Desktop.
summarized consecutive images at current directory to one PDF
#!/bin/zsh
require=false
[[ ! -f `which pdftk` ]] && echo 'Require Package pdftk' && require=true
[[ ! -f `which convert` ]] && echo 'Require Package convert (ImageMagick)' && require=true
if [[ $require == true ]] ; then
exit
fi
mkdir .tmp >/dev/null 2>&1
i=0
for FIMG in `ls` ; do
i=$[ $i + 1 ]
if [[ 'jpeg' == ${FIMG##*.} ]] ; then
mv $FIMG ${FIMG%jpeg}jpg
fi
XTNS=${FIMG##*.}
if [[ 'png' == $XTNS ]] ; then
FPDF=${FIMG%png}pdf
convert -page A4 $FIMG $FPDF
[[ -f $FIMG ]] && yes | mv -f $FIMG .tmp/
elif [[ 'jpg' == $XTNS ]] ; then
FPDF=${FIMG%jpg}pdf
convert -page A4 -compress jpeg $FIMG $FPDF
[[ -f $FIMG ]] && yes | mv -f $FIMG .tmp/
elif [[ 'pdf' == $XTNS ]] ; then
FPDF=$FIMG
fi
APDF[$i]=$FPDF
done
TIME=`php -r 'echo time();'`
pdftk $APDF cat output ${TIME}.pdf && rm $APDF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment