8

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.

3 Answers 3

6

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.

3

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.

0

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.

3
  • 2
    I know you can compress the pictures, but that is not what I am asking. Furthermore, using this method only seems to compress all the pictures of a give file type (i.e. it seems to only compress the JPEGs unless you go and repeat the process on a PNG). The PNG images are still far larger than the JPEGs, so I want to replace all the PNGs with JPEG versions as stated in the question. Commented Feb 22, 2016 at 10:50
  • First, this method does compress all pictures, not as you think. Here (i.imgur.com/GF9S9FA.png) I performed compression by selecting a JPEG image, the process went along with the PNG image as well. However, even if you succeed in converting PNG to JPEG, you'll end breaking the link which requests re-inserting the newly converted pictures. Remember, PNG (lossless) will always be far larger than JPEG (lossy compression). If this answer doesn't satisfy you, I'll delete it.
    – Sanny
    Commented Feb 22, 2016 at 11:49
  • 3
    This method compresses the picture by downgrading resolution and cropping hidden area. Image format is reserved, so no matter what original format is, it is preserved.
    – Yvon
    Commented Jul 10, 2017 at 21:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .