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:
- Create your document as normal, save your final version as .docx, and close word
- Unzip your docx file using whatever you prefer. powershell, 7zip, unzip.exe, etc
- Delete the png image file located at
[extract folder]\word\media\Image1.png
- Copy your webp image to the same folder and rename to
Image1.png
- 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"