Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
May 25, 2024

Conversation

YellowTech
Copy link
Contributor

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:

  • New and correctly working:

    • Processed 50 files (320.2 MB) in 2.7s (18.3 f/s).
    • python -m optimize_images ./conv -ke 21.77s user 1.02s system 805% cpu 2.829 total
  • Old with broken EXIF

    • Processed 50 files (320.2 MB) in 2.7s (18.2 f/s).
    • python -m optimize_images ./conv -ke 21.69s user 1.08s system 806% cpu 2.823 total
  • Old without '-ke' parameter

    • Processed 50 files (320.2 MB) in 2.7s (18.6 f/s).
    • python -m optimize_images ./conv 21.66s user 0.90s system 821% cpu 2.747 total

@YellowTech
Copy link
Contributor Author

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

@victordomingos victordomingos merged commit 0da9c8c into victordomingos:master May 25, 2024
@victordomingos
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants