Skip to content

Instantly share code, notes, and snippets.

@dmccreary
Created April 6, 2025 15:12
Show Gist options
  • Save dmccreary/c785ab6d2072e4cd0e61eb1d4e6b68f2 to your computer and use it in GitHub Desktop.
Save dmccreary/c785ab6d2072e4cd0e61eb1d4e6b68f2 to your computer and use it in GitHub Desktop.
List Large Images in Microsoft PPTX file
#!/bin/sh
# get the parameter
echo "working on" "$1"
rm -r /tmp/big-images 2> /dev/null
mkdir /tmp/big-images
# copy the ppt file to /tmp
cp "$1" /tmp/big-images
# rename it to be .zip
mv "/tmp/big-images/$1" "/tmp/big-images/$1.zip"
# unzip it
echo "unzipping /tmp/big-images/$1.zip"
unzip -q "/tmp/big-images/$1.zip" -d /tmp/big-images
# find images above 10K and save with size info to temp file
find /tmp/big-images/ppt/media/ -type f -size +10k | while read -r image; do
# Get file size in bytes (macOS compatible)
size=$(ls -l "$image" | awk '{print $5}')
name=$(basename "$image")
slide=$(grep -l "$name" /tmp/big-images/ppt/slides/_rels/*.rels | sed 's/.*slide\(.*\).xml.rels/\1/')
# Format size with K or M suffix (macOS compatible)
if [ "$size" -gt 1048576 ]; then
formatted_size=$(echo "scale=1; $size/1048576" | bc)
formatted_size="${formatted_size}M"
else
formatted_size=$(echo "scale=1; $size/1024" | bc)
formatted_size="${formatted_size}K"
fi
# Output to temp file: original size (for sorting), formatted size, name, slide
echo "$size $formatted_size $name $slide" >> /tmp/big-images/sizes.txt
done
# Sort by size (largest first) and display results
sort -rn /tmp/big-images/sizes.txt | awk '{print $2 "\t" $3 "\tSlide: " $4}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment