Skip to content

Instantly share code, notes, and snippets.

@codewithpassion
Created May 22, 2018 01:05
Show Gist options
  • Save codewithpassion/a221c9d48d655e274a35e3e0ecd93d96 to your computer and use it in GitHub Desktop.
Save codewithpassion/a221c9d48d655e274a35e3e0ecd93d96 to your computer and use it in GitHub Desktop.
Powerpoint compressor
#!/bin/bash
for pptName in ./*.pptx; do
mkdir "${pptName}_folder"
cd "${pptName}_folder"
unzip "../$pptName"
cd ppt/media
if [ -f "media1.mp4" ]; then
for filename in ./*.mp4; do
ffmpeg -i "$filename" -vf scale=1920:1080 -strict -2 -c:v libx264 -crf 30 -preset slow "${filename}_small.mp4"; cat "${filename}_small.mp4" > "$filename"; rm "${filename}_small.mp4"
#ffmpeg -i "$filename" -vf scale=1280:720 -strict -2 -c:v libx264 -crf 30 -preset slow "${filename}_small.mp4"; cat "${filename}_small.mp4" > "$filename"; rm "${filename}_small.mp4"
done
fi
cd ../../
NEW_FILE=$(basename "${pptName}" .pptx)
zip -r "../${NEW_FILE}_small.pptx" ./*
# zip -r "../${pptName}_small_720.pptx" ./*
cd ..
rm -rf "${pptName}_folder"
done
#!/bin/bash
for pptName in ./*.pptx; do
mkdir "${pptName}_folder"
cd "${pptName}_folder"
unzip "../$pptName"
cd ppt/media
if [ -f "media1.mp4" ]; then
for filename in ./*.mp4; do
ffmpeg -i "$filename" -vf scale=1280:720 -strict -2 -c:v libx264 -crf 30 -preset slow "${filename}_small.mp4"; cat "${filename}_small.mp4" > "$filename"; rm "${filename}_small.mp4"
done
fi
cd ../../
NEW_FILE=$(basename "${pptName}" .pptx)
zip -r "../${NEW_FILE}_small_720.pptx" ./*
cd ..
rm -rf "${pptName}_folder"
done
#!/bin/bash
for pptName in ./*.pptx; do
mkdir "${pptName}_folder"
cd "${pptName}_folder"
unzip "../$pptName"
cd ppt/media
jpgExists=`ls -1 *.jpeg 2>/dev/null | wc -l`
if [ $jpgExists != 0 ]; then
for filename in ./*.jpeg; do
IMAGE_NAME=$(basename "$filename" .jpeg)
echo "Converting ${filename}"
convert -quality 90% -resize 1920x1080 "$filename" "${IMAGE_NAME}.jpeg"
done
fi
tiffExists=`ls -1 *.tiff 2>/dev/null | wc -l`
if [ $tiffExists != 0 ]; then
for filename in ./*.tiff; do
IMAGE_NAME=$(basename "$filename" .tiff)
echo "Converting ${filename}"
convert -quality 90% -resize 1920x1080 "$filename" "${IMAGE_NAME}.jpeg"
rm "${filename}"
done
fi
pngExists=`ls -1 *.png 2>/dev/null | wc -l`
if [ $pngExists != 0 ]; then
for filename in ./*.png; do
IMAGE_NAME=$(basename "$filename" .png)
echo "Converting ${filename}"
convert -quality 90% -resize 1920x1080 "$filename" "${IMAGE_NAME}.jpeg"
rm "${filename}"
done
fi
jpgExists=`ls -1 *.jpg 2>/dev/null | wc -l`
if [ $jpgExists != 0 ]; then
for filename in ./*.jpg; do
IMAGE_NAME=$(basename "$filename" .jpg)
echo "Converting ${filename}"
convert -quality 90% -resize 1920x1080 "$filename" "${IMAGE_NAME}.jpeg"
rm "${filename}"
done
fi
cd ../slides/_rels
for filename in ./*.rels; do
sed -i 's/\.tiff/.jpeg/g' $filename
sed -i 's/\.png/.jpeg/g' $filename
sed -i 's/\.jpg/.jpeg/g' $filename
done
cd ../../..
NEW_FILE=$(basename "${pptName}" .pptx)
zip -r "../${NEW_FILE}_pix.pptx" ./*
cd ..
rm -rf "${pptName}_folder"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment