jbaiter / jpegtran-cffi

Fast, (mostly) lossless JPEG transformations with Python
http://jpegtran-cffi.readthedocs.org
MIT License
146 stars 23 forks source link

Metadata like exif and xmp is lost on save #39

Open Dobatymo opened 1 year ago

Dobatymo commented 1 year ago

Not sure why though. According to libjpeg-turbo TJXOPT_COPYNONE needs to be set to not copy it.

Test using the test file in the test folder.

from jpegtran import JPEGImage
img = JPEGImage("test/test.jpg")
img.save("test/test-save.jpg")
img.rotate(90).save("test/test-rotate.jpg")
img.crop(0, 0, 64, 64).save("test/test-crop.jpg")

test-save.jpg keeps the metadata, the other two not.

mixmastamyk commented 3 weeks ago

I'm using it for this:

corrected = photo.exif_autotransform()

This used to preserve and update the Exif.

jpegtran -outfile foo2.jpeg -rotate 90 foo.jpeg loses the Exif as well.

jpegtran -rotate 90 -copy all -outfile foo2.jpeg foo.jpeg copies it, but the orientation needs updating.

Looking thru the code, not sure how it ever worked. There doesn't seem to be any affordance for the copy parameter, and it isn't a member of the transform options. Maybe the default in the C code changed at some point, but doesn't look recently updated either.

I had to change my code to a double subprocess.call of jpegtran and exiftool. :-(