4

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
  • 683

1 Answers1

2

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
  • 10,914