victordomingos / optimize-images

A command-line interface (CLI) utility written in pure Python to help you reduce the file size of images.
https://no-title.victordomingos.com/projects/optimize-images
MIT License
272 stars 49 forks source link

Fix keep EXIF data -ke / --keep-exif with BytesIO buffer #42

Closed YellowTech closed 5 months ago

YellowTech commented 1 year ago

As mentioned in #40 EXIF data is destroyed even when using the -ke flag. This is due to piexif.transplant expecting a subscriptable object (usually file path) which a BytesIO buffer itself is not. This is fixed by letting transplant use the buffer as an array and copying the resulting image into a new buffer which then replaces the old one.

This does not affect performance in any meaningful way, here are some Benchmarks on 50 giant (9mb) jpgs:

YellowTech commented 5 months ago

Can we merge this? If this gets through I could work on HEIC support with pillow-heif.

victordomingos commented 5 months ago

Done. I will perform some testing before issuing the next release.m, so it may take a while before it comes to pip.