Open varnav opened 2 years ago
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.
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)?
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.
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.
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)
pip install optimize-images==1.4
does not suffer from this problem
Describe the bug Destroys EXIF data despite
--keep-exif
To Reproduce
Optimized image will have it's EXIF data wiped.
Expected behavior Image gets optimized, EXIF data intact.