9

I have a large PowerPoint file with many embedded images, some of which are JPEGs and some PNGs. To make the file as small as possible I would like all the PNG images to be converted to JPEGs.

This can be done by manually saving each image, converting it, and re-adding it to the presentation, but it takes a lot of time. Is there functionality to do a batch conversion in MS Powerpoint (2016), or some other method to achieve this more efficiently?


Added: I realise that images can be compressed in PowerPoint, and I have done that already. But that does not reduce the file size as much as replacing the PNGs with JPEGs, since the PNGs are much much larger files – hence the question.

4 Answers4

7

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.

Ben N
  • 42,308
4

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.

slhck
  • 235,242
1

If you're seeking to minimise the pptx file, regardless of setting image formats, select a picture and from the Ribbon menu, pick Format and find the button Compress Pictures. Un-tick Apply only to this picture to apply to all pictures.

Optional: set the radio button to E-mail 96 ppi. That will downgrade the resolution and thus create lighter pptx. Tick Delete cropped areas of pictures to discard unused portions hidden with the Crop button.

Sanny
  • 1,627
1

It might be more important to you to get a small file than keep it in pptx format, e.g. to share a draft. If so,

  • Export as PDF and
  • Optimize for "best for electronic distribution" in the save dialog below the filename.

It got me a 42MB pptx file down to a 5MB PDF.

cachius
  • 859