How to convert multiple embedded PNGs to JPEGs in Powerpoint file?

You can use PowerShell! Since modern Office documents are actually ZIP files containing mostly XML files, we can manipulate them fairly easily without relying on any Office components. I wrote this script for you:

[CmdletBinding()]
Param(
    [Parameter(Mandatory = $true)][string]$File,
    [Parameter()][int]$Quality = 50
)
Add-Type -AssemblyName System.IO.Compression
Add-Type -AssemblyName System.Drawing
$fs = New-Object System.IO.FileStream (Resolve-Path $File), 'Open'
$zip = New-Object System.IO.Compression.ZipArchive $fs, 'Update'
$zip.Entries | ? {$_.FullName -like 'ppt/media/*.png'} | % {
    $s = $_.Open()
    $img = [System.Drawing.Image]::FromStream($s)
    $s.Position = 0
    $codec = [System.Drawing.Imaging.ImageCodecInfo]::GetImageDecoders() | ? {$_.FormatId -eq [System.Drawing.Imaging.ImageFormat]::Jpeg.Guid}
    $qualityprop = [System.Drawing.Imaging.Encoder]::Quality
    $encodeparams = New-Object System.Drawing.Imaging.EncoderParameters 1
    $encodeparams.Param[0] = New-Object System.Drawing.Imaging.EncoderParameter $qualityprop, $Quality
    $img.Save($s, $codec, $encodeparams)
    $s.SetLength($s.Position)
    $s.Close()
}
$zip.Dispose()

It opens the given PPTX file as a ZIP archive, finds each embedded PNG image, and converts that image to a JPG. It doesn't update the extension of the file within the archive, but PowerPoint doesn't seem to care (tested on PowerPoint 2016 on Windows 10). If you want it to attempt to work with all image types (I have not tested other formats), change this line:

$zip.Entries | ? {$_.FullName -like 'ppt/media/*.png'} | % {

To this:

$zip.Entries | ? {$_.FullName.StartsWith('ppt/media/')} | % {

Save the script as a .ps1 file, e.g. pptxjpg.ps1. If you haven't already, follow the instructions in the Enabling Scripts section of the PowerShell tag wiki. You can then run it from a PowerShell prompt like this:

.\pptxjpg.ps1 C:\path\to\presentation.pptx

It takes an optional parameter specifying the JPG quality, defaulted to 50. If you want to save even more space, you might specify a lower value, like so:

.\pptxjpg.ps1 C:\path\to\presentation.pptx -Quality 20

When I tested this latter command, it reduced the size of a presentation containing a high-resolution screenshot and a medium-size diagram from 982 KB to 253 KB.


If you have Python, you can use this script that I wrote:

https://github.com/slhck/compress-pptx

All you need is ImageMagick installed (e.g. apt install imagemagick).

Then, simply install it and point it to your file:

pip3 install --user compress-pptx
compress-pptx /path/to/file.pptx

It'll convert all embedded PNG and TIFF images that are larger than 1 MiB, compressing them to lossy JPEGs. Note that this skips images with transparency. See -h for more options and run it with -v to get more info about the compression results.