3

Recently Office has added the ability to read WebP images, and to integrate them into Office documents as pictures.

The WebP format has many advantages, specifically it allows massively smaller file sizes with excellent image quality, compared to JPEG and other formats. Transparency masks are also fully supported.

Unfortunately, it seems that WebP images that are embedded in Office documents are saved internally as PNG, which multiplies the memory requirements for saving the images.

Or is there a specific way to ensure that WebP images embedded into Office documents are saved unchanged, in their original WebP format and compression?

David.P
  • 459
  • 2
  • 6
  • 27
  • 1
    PowerPoint is almost certainly including the PNG version of the image for backward compatibility with PPT versions that can't yet use WebP pictures. Are both included or is it simply converting WebP to PNG, saving the PNG and tossing the original? – Steve Rindsberg Jul 09 '22 at 17:08
  • 1
    {later} I tested a sample WebP image here (https://filesamples.com/formats/webp) in PPT 2016 and found that it only stored the WebP image, no PNG. The resulting saved PPTX was only a few bytes larger than the original WebP image. What version of PPT do you have/on what platform? And is there a sample WebP image you could make available to test with? – Steve Rindsberg Jul 10 '22 at 15:40
  • Whoa Steve, that would be good news. If I insert that WebP image from your link into an empty PowerPoint file and save the file, the PPTX file has 12.3 MB. If I right-click on the image in PowerPoint and choose “Save as Picture”, PowerPoint saves it as PNG, however in low resolution. When I unzip the PPTX file, the image can be found as PNG in original resolution with a size of 12.2 MB. I wonder what compression settings you use in PowerPoint so that the image appears to be saved in its original format. Or maybe the image has been re-compressed to JPEG (and possibly re-sampled) in your file? – David.P Jul 12 '22 at 15:07
  • I'm using Office 365 in the latest (beta) version 2208 Build 16.0.15504.20000 32bit. – David.P Jul 12 '22 at 15:08
  • My compression setting is at the default, High Fidelity. But here's something interesting: I inserted the original WebP file above, and also a much smaller one. The large file was preserved in the PPTX as a WebP, the smaller one was converted to PNG. The smaller one had a transparent b/g ... I wonder if that has any bearing on what we're seeing here. – Steve Rindsberg Jul 13 '22 at 15:12
  • That's an interesting finding Steve. I still wonder however why your PowerPoint preserves the above WebP file and mine doesn't. I have image compression also set to High Fidelity. – David.P Jul 14 '22 at 16:33

1 Answers1

1

I tried a few different ways of disabling compression/discarding image data etc, but didn't have any luck doing this natively in Word.

This is more of a nuclear option for certain use cases, but it does work - Replacing the internal png files with the original webp images:

  1. Create your document as normal, save your final version as .docx, and close word
  2. Unzip your docx file using whatever you prefer. powershell, 7zip, unzip.exe, etc
  3. Delete the png image file located at [extract folder]\word\media\Image1.png
  4. Copy your webp image to the same folder and rename to Image1.png
  5. Now select all of the extracted folders and [Content_Types].xml, and re-zip them to a new .docx file

And you're done! Now you've got a much smaller word file that still displays your webp images.


Downsides:

  • If you open the document and re-save it, the image gets converted again, to an even larger .bin format (though that can be replaced the same way)
  • While small edits like resizing the image (and even cropping) work fine with this method, I'm not sure how far I would trust it with effects and such
  • You're basically removing any backwards-compatibility for viewing these files if someone's version of Office is older than yours

Here's an example that spells out the steps using a powershell script in one go

# extract the docx
mkdir "c:\test\extract"
Rename-Item -Path "C:\test\huge.docx" -NewName "C:\test\huge.zip"
Expand-Archive -Path "C:\test\huge.zip" -DestinationPath "c:\test\extract\"

# replace a png with webp
Get-Item "C:\test\extract\word\media\image1.png" | Remove-Item
Copy-Item "C:\test\test.webp C:\test\extract\word\media\image1.png"

# re-zip to docx
Get-Item -Path "C:\test\extract\*" | Compress-Archive -DestinationPath "c:\test\small.zip"
Rename-Item -Path "C:\test\small.zip" -NewName "C:\test\small.docx"

# clean up
Rename-Item -Path "C:\test\huge.zip"  -NewName "C:\test\huge.docx"
Remove-Item -Recurse "C:\test\extract"
Cpt.Whale
  • 4,501
  • 2
  • 13
  • 25
  • That's a very cool hack. I'll definitely give this a try in case I need to include an extremely high resolution image (particularly with transparency layer) in a PowerPoint presentation -- without the file size getting excessively large. For example, I have a product rendering here with transparent background at a size of 70 megapixels that occupies 44 MB as PNG, and only 450 KBytes as WebP, and that's with exact preservation of the background transparency, and with almost undetectable compression artifacts in the image layer. The WebP image is thus almost 100 times, or 99%, smaller! – David.P Jul 12 '22 at 15:27
  • 1
    @David.P I also found that adding .webp files, then saving as PDF seemed to dramatically reduce the overall size while keeping transparency (3.1MB .png, 1.3MB .webp, 70KB .pdf). Though you're discarding ppt features of course. I'm curious if the same applies to your gigantic images – Cpt.Whale Jul 12 '22 at 16:07