!/usr/bin/fish
if test -z $argv[1]
echo directory missing
exit 1
end
set d $argv[1]
if test ! -d $d
echo $d is not a directory
exit 2
end
alex@melanobombus ~/D/R/One Page Dungeon Contest> type pdf-shrink
pdf-shrink is a function with definition
# Defined in /home/alex/.config/fish/conf.d/pdf-shrink.fish @ line 1
function pdf-shrink --description 'Optimize PDF'
# https://ghostscript.com/blog/optimizing-pdfs.html
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH \
-dConvertCMYKImagesToRGB \
-dGrayImageFilter=/DCTEncode -dColorImageFilter=/DCTEncode \
-dAutoFilterGrayImages=false -dAutoFilterColorImages=false \
-dDownsampleColorImages=true -dDownsampleGrayImages=true -dDownsampleMonoImages=true \
-dColorImageResolution=150 -dGrayImageResolution=150 -dMonoImageResolution=150 \
-dColorImageDownsampleThreshold=1.1 -dGrayImageDownsampleThreshold=1.1 -dMonoImageDownsampleThreshold=1.1 \
-dPreserveHalftoneInfo=false -dPreserveOverprintSettings=false \
-dTransferFunctionInfo=/Apply -dUCRandBGInfo=/Remove \
-sOutputFile=$argv[2] $argv[1]
end
for f in $d/*.pdf
echo Shrinking $f
pdf-shrink "$f" "$f-x" && mv "$f-x" "$f"
end
echo Done