Skip to content

ystyleb/pptx-compressor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pptx-compressor

Shrink a bloated .pptx file by 50–70% without touching a single slide, word, layout, animation, or embedded font.

This is a Claude Code Skill, but the underlying script is a plain Python CLI you can use standalone.

What gets compressed — and what doesn't

A .pptx is a ZIP archive. The slide markup (XML) is a few hundred KB at most; the bulk is almost always embedded media. This tool only touches media:

Asset Action
Videos (.mp4) Re-encoded with ffmpeg, H.264, configurable CRF
JPEGs Re-encoded at configurable quality, optionally downsampled to 1920px
PNGs (with real alpha) Optimized in place, kept as PNG
PNGs (no alpha) — aggressive mode only Converted to JPEG; [Content_Types].xml and all .rels references patched
Slide XML, animations, themes, charts, tables Not touched
Embedded fonts (ppt/fonts/*.fntdata) Not touched — removing them causes layout drift on machines without the same fonts

Real result from a 262 MB presentation with 2 videos, 168 images and 13 embedded fonts:

Before : 262.0 MB
After  :  81.0 MB   (-69.1%)
Stats  : Stats(jpeg=30, png_keep=35, png_to_jpg=123, videos=2, skipped=15, errors=0)

Installation

As a Claude Code Skill

git clone https://github.com/ystyleb/pptx-compressor ~/.claude/skills/pptx-compressor

Then in Claude Code, any mention of "compress PPT", "PPTX 太大", "shrink this deck" etc. will invoke the skill.

As a plain Python CLI

git clone https://github.com/ystyleb/pptx-compressor
cd pptx-compressor
pip install Pillow
# macOS
brew install ffmpeg
# Debian/Ubuntu
# sudo apt install ffmpeg

python3 scripts/compress_pptx.py path/to/deck.pptx

Requirements

  • Python 3.9+
  • Pillowpip install Pillow
  • ffmpeg on PATH (skip with --skip-video if the deck has no videos)

Usage

python3 scripts/compress_pptx.py INPUT.pptx [-o OUTPUT.pptx]
                                [--level {conservative,medium,aggressive}]
                                [--skip-video]
                                [--quiet]

Compression levels

Level JPEG q Video CRF Max edge No-alpha PNG → JPG Typical savings
conservative 85 24 no ~30%
medium 80 28 1920px no ~50%
aggressive (default) 80 28 1920px yes ~70%

The default is aggressive because slide decks are almost always projected or viewed at ≤1080p, where a 4096px source photo is strictly waste. If you're printing or archiving originals, use conservative.

Examples

# Overwrite in place; original is saved to deck.bak.pptx alongside
python3 scripts/compress_pptx.py deck.pptx

# Keep original untouched, write to a new file
python3 scripts/compress_pptx.py deck.pptx -o deck.small.pptx

# I care about photo quality more than file size
python3 scripts/compress_pptx.py deck.pptx --level conservative

# Don't re-encode videos (I've already optimized them)
python3 scripts/compress_pptx.py deck.pptx --skip-video

Rollback

If anything looks wrong after compression:

mv deck.bak.pptx deck.pptx

How it works (and why it's safe)

.pptx is just a ZIP archive. Every image and video reference inside slide XML goes through ppt/slides/_rels/slideN.xml.rels:

<Relationship Id="rId3" Target="../media/image42.png" .../>

If you re-encode image42.png as a JPEG, you need to:

  1. Rename it to image42.jpg on disk.
  2. Update every .rels file that refers to it.
  3. Make sure [Content_Types].xml declares <Default Extension="jpg" ContentType="image/jpeg"/>.

Skip any of these and PowerPoint shows "some content could not be displayed" placeholders.

This tool does all three, and then runs a reference-integrity check before writing the output: every Target= in every .rels must resolve to a real file inside the archive, otherwise the script aborts without touching the original. It also runs a final sanity pass (unzip, parse key XMLs, open a sample image) on the output.

Things this tool does not do and is explicit about not doing:

  • It does not remove embedded fonts, even though they're often the largest single remaining category. Removing fonts can make the deck look wrong on machines that don't have them installed. If you control the playback machine and want to strip fonts, do it by hand.
  • It does not claim the output is "identical". Re-encoding is lossy. The honest framing is: visually indistinguishable in normal presentation use, slightly lower quality if you pixel-peep at 1:1.
  • It does not modify .ppt (legacy binary). Open it in PowerPoint/Keynote and "Save As .pptx" first.

License

MIT. See LICENSE.

Acknowledgements

Built with Claude Code. Issues and PRs welcome.

About

Shrink .pptx files by 50-70% without touching slides, layout, animations, or embedded fonts. A Claude Code Skill (and plain Python CLI) that re-encodes videos with ffmpeg, optimizes images with Pillow, and safely patches PNG->JPG rels.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages