Skip to main content

compress-pptx

PyPI version

All Contributors

Compress a PPTX or POTX file, converting all PNG/TIFF images to lossy JPEGs.

Contents:

What it does

When copy-pasting images to PowerPoint presentations, these sometimes get inserted as lossless versions, blowing up the size of the presentation.

This script takes all PNG or TIFF images part of the presentation which are larger than a given threshold (1 MiB by default), converts them to a lossy JPEG variant, and creates a new PPTX file.

⚠️ This is not the same as compressing images with PowerPoint's own functionality. You may still need to do this to reduce the size of your presentation!

By default, transparent raster images and EMF vector images are skipped to prevent graphics issues (since JPEG doesn't support transparency). If you want to force conversion anyway, their transparent parts will be replaced with white (although you can choose another color with -t). EMF conversion may also require LibreOffice and -l on systems where ImageMagick cannot read EMF files.

Requirements

  • Operating system: macOS or Linux
    • Note: Under Linux, you need LibreOffice installed to convert embedded EMF files
  • Python 3.9 or higher
  • ImageMagick (either version 6.x with convert/identify commands or version 7.x with magick command)
  • Optionally: ffmpeg for media files

Under Ubuntu, get ImageMagick via:

apt install imagemagick

Under macOS, install it with Homebrew:

brew install imagemagick

For ffmpeg, use the static builds from ffmpeg.org.

Installation

Simply run it via uv:

uvx compress-pptx

Or install via pipx. Or manually via pip:

pip3 install --user compress-pptx

Usage

Call compress-pptx and point it to a PPTX or POTX file. It'll compress the images and output another compressed file next to it.

For more options, see the -h output:

usage: compress-pptx [-h] [-o OUTPUT] [-s SIZE] [-q QUALITY] [-t TRANSPARENCY]
                     [--no-skip-transparent-images] [-v] [-f] [-m] [-j] [-l]
                     [--num-cpus NUM_CPUS] [--extract EXTRACT]
                     [--ffmpeg-crf FFMPEG_CRF]
                     [--ffmpeg-video-codec FFMPEG_VIDEO_CODEC]
                     [--ffmpeg-audio-codec FFMPEG_AUDIO_CODEC]
                     [--ffmpeg-extra-options FFMPEG_EXTRA_OPTIONS]
                     [--ffmpeg-path FFMPEG_PATH]
                     input

positional arguments:
  input

options:
  -h, --help            show this help message and exit
  -o OUTPUT, --output OUTPUT
                        Output file (default: None)
  -s SIZE, --size SIZE  Minimum size threshold in bytes. Also accepts the
                        suffixes k/M/G or KiB/MiB/GiB (default: 1MiB)
  -q QUALITY, --quality QUALITY
                        JPEG output quality (0-100) (default: 85)
  -t TRANSPARENCY, --transparency TRANSPARENCY
                        Replace transparency with color (default: white)
  --no-skip-transparent-images
                        Convert transparent images to JPEG (will replace
                        transparency with background color). By default,
                        transparent images are skipped to preserve transparency.
  -v, --verbose         Show additional info (default: False)
  -f, --force           Force overwriting output file (default: False)
  -m, --compress-media  Compress other media types such as audio and video
                        (requires ffmpeg) (default: False)
  -j, --recompress-jpeg
                        Recompress jpeg images (default: False)
  -l, --use-libreoffice
                        Use LibreOffice to compress EMF files (only way to
                        compress EMF files under Linux) (default: False)
  --num-cpus NUM_CPUS   Number of CPUs to use (default: all available CPUs)
  --extract EXTRACT     Extract all media from the presentation to the
                        specified directory (default: None)
  --ffmpeg-crf FFMPEG_CRF
                        FFmpeg CRF value for video encoding (e.g., 23 for
                        libx264) (default: None)
  --ffmpeg-video-codec FFMPEG_VIDEO_CODEC
                        FFmpeg video codec (e.g., libx264 for best PowerPoint
                        compatibility) (default: None)
  --ffmpeg-audio-codec FFMPEG_AUDIO_CODEC
                        FFmpeg audio codec (e.g., aac, libopus, libmp3lame)
                        (default: None)
  --ffmpeg-extra-options FFMPEG_EXTRA_OPTIONS
                        Extra FFmpeg options as a single string (e.g.,
                        '-preset slow -tune stillimage') (default: None)
  --ffmpeg-path FFMPEG_PATH
                        Path to ffmpeg executable (default: ffmpeg)

For example, to compress presentation.pptx and output to presentation-compressed.pptx with a quality of 75:

compress-pptx -o presentation-compressed.pptx -q 75 presentation.pptx

If you have ffmpeg installed, you can also compress audio and video files embedded in the presentation with the -m flag:

compress-pptx -m presentation.pptx

Transparent images are automatically skipped by default to preserve transparency. If you want to force conversion of transparent images to JPEG (replacing transparency with a background color), use the --no-skip-transparent-images flag:

compress-pptx --no-skip-transparent-images presentation.pptx

Extracting media

To extract all media files from a presentation, use the --extract option with a directory path:

compress-pptx --extract ./media presentation.pptx

This will create the media directory (if it doesn't exist) and extract all images, audio, and video files from the presentation into it.

FFmpeg encoding options

When using -m to compress media files, you can customize the FFmpeg encoding settings:

compress-pptx -m --ffmpeg-video-codec libx265 --ffmpeg-crf 34 presentation.pptx

Note that the default is libx264 and CRF 23.

You can pass additional FFmpeg options using --ffmpeg-extra-options:

compress-pptx -m --ffmpeg-video-codec libx264 --ffmpeg-extra-options '-preset slow -tune stillimage' presentation.pptx

To see available options for a specific encoder, run:

ffmpeg -h encoder=libx264

Contributors

caydey
caydey

💻

License

MIT License

Copyright (c) 2021-2025 Werner Robitza

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Metadata

Release files for compress-pptx 1.3.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for compress-pptx 1.3.2
File Size Uploaded
compress_pptx-1.3.2.tar.gz 11.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for compress-pptx 1.3.2
File Interpreter ABI Platform
compress_pptx-1.3.2-py3-none-any.whl Python 3 none any Details

Total release size: 25.3 kB

Release files / compress_pptx-1.3.2.tar.gz

Download URL compress_pptx-1.3.2.tar.gz
Size 11.1 kB
Tags Source
SHA-256 checksum
How to use checksums
0ea9deb511f4e1423fe46c3cfbb79b47ae63a98a73d96c4a4836bfe575ae3a23
BLAKE2b-256 checksum
How to use checksums
4305ad007fae037ccc51060700f98269863641ed8bbcbf7ff323dc5cec341382
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / compress_pptx-1.3.2-py3-none-any.whl

Download URL compress_pptx-1.3.2-py3-none-any.whl
Size 14.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e7d459ee5881b78be800a9439a9d0dff3a399c72ce4b76dde54f643b3fe960b5
BLAKE2b-256 checksum
How to use checksums
4815a330045f4a21afef7c84c51e9e623ce92c8d155b5098c5aa2b1213f73a61
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release history Release notifications | RSS feed

1.3.3

2 release files

This release

1.3.2 This release

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.10.1

2 release files

0.10.0

2 release files

0.9.0

2 release files

0.8.3

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page