Skip to content

Instantly share code, notes, and snippets.

@L-U-C-K-Y
Forked from erkie/README.md
Last active February 18, 2021 17:45
Show Gist options
  • Save L-U-C-K-Y/b340a02eab59ea3467924cfebe9d57b1 to your computer and use it in GitHub Desktop.
Save L-U-C-K-Y/b340a02eab59ea3467924cfebe9d57b1 to your computer and use it in GitHub Desktop.
Compress PPTX
#!/bin/bash
if [[ -z $1 ]]; then echo $0 input_pptx [output_pptx]; exit; fi
if [[ ! -f $1 ]]; then echo File $1 not found; exit; fi
if [[ -z $2 ]]; then out=${1/.pptx/-compressed.pptx}; else out=$2; fi
[[ -d xtractd ]] && rm -i -r xtractd
[[ -f $out ]] && rm -i "$out"
unzip "$1" -d xtractd
cd xtractd/ppt/media
for x in *.tiff; do sips -s format png $x --out ${x/.tiff/.png}; done
rm *.tiff
# resize images to 1920
sips -Z 1920 *.png
sips -Z 1920 *.jpg
# compress images
/Applications/ImageOptim.app/Contents/MacOS/ImageOptim *.png *.jpg *.jpeg *.svg
cd ..
sed -i '' -e 's/\(Target="[^"]*\)tiff"/\1png"/g' slides/_rels/*.rels
# sed -i '' -e 's/\(typeface="\)[^"]*"/\1Calibri"/g' slides/*.xml notesSlides/*.xml slideLayouts/*.xml slideMasters/*.xml
cd ..
zip -r "../$out" *
cd ..
rm -r xtractd
# open "$out"
@L-U-C-K-Y
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment