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

Destroys EXIF data despite --keep-exif #40

Open
varnav opened this issue May 24, 2022 · 6 comments
Open

Destroys EXIF data despite --keep-exif #40

varnav opened this issue May 24, 2022 · 6 comments

Comments

@varnav
Copy link
Contributor

varnav commented May 24, 2022

Describe the bug
Destroys EXIF data despite --keep-exif

To Reproduce

pip3 install pillow optimize-images
optimize-images --keep-exif .

Optimized image will have it's EXIF data wiped.

Expected behavior
Image gets optimized, EXIF data intact.

@varnav
Copy link
Contributor Author

varnav commented May 25, 2022

Did some debugging, here's what happening:

File "C:\src\optimize-images\optimize_images\img_optimize_jpg.py", line 80, in optimize_jpg
piexif.transplant(os.path.expanduser(task.src_path), tmp_buffer)
File "C:\src\optimize-images\venv\lib\site-packages\piexif_transplant.py", line 26, in transplant
if image[0:2] == b"\xff\xd8":
TypeError: '_io.BytesIO' object is not subscriptable

It seems that transplant wants real file as 2nd parameter, but gets BytesIO instead. At same time it seems that BytesIO can be used as a 3rd parameter.

@victordomingos
Copy link
Owner

victordomingos commented May 25, 2022

Hi! Thanks for reporting this issue. It seems to be happening on piexif's side, but it needs to be investigated. Does it happen always, regardless of the image file being processed?

Can you please provide the output of optimize-images --version (please anonymise the file paths if necessary)?

@varnav
Copy link
Contributor Author

varnav commented May 25, 2022

Looks like here:

piexif.transplant(os.path.expanduser(task.src_path), tmp_buffer)

you're giving tmp_buffer that is BytesIO. But transplant wants path to actual file.

Always the same.

I'm using latest revision from this repo.

@victordomingos
Copy link
Owner

I understand. Thanks for the details. It should not be very complicated to fix, but I can't promise a date.
I will try to fix in a few days it if no one submits a pull request first.

@varnav
Copy link
Contributor Author

varnav commented May 26, 2022

You actually don't need piexif, Pillow can handle this:

Load all EXIF data:

exif = img.info['exif']

Save it:

img.save('P4072956_thumb.jpg', exif=exif)

@YellowTech
Copy link
Contributor

pip install optimize-images==1.4 does not suffer from this problem

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

No branches or pull requests

3 participants