wanadev / mozjpeg-lossless-optimization

Python library to optimize JPEGs losslessly using MozJPEG
Other
28 stars 2 forks source link

Copy Metadata #4

Open staceellis opened 1 year ago

staceellis commented 1 year ago

Hi,

How can I use '-copy all' to carry over all metadata to output .jpeg?

I'm using the example code:

with open(input_image, "rb") as input_jpeg_file:
    input_jpeg_bytes = input_jpeg_file.read()

output_jpeg_bytes = mozjpeg_lossless_optimization.optimize(input_jpeg_bytes)

with open(output_image, "wb") as output_jpeg_file:
    output_jpeg_file.write(output_jpeg_bytes)
flozz commented 1 year ago

Hello,

There is currently no options implemented at all, so there is no way to allow copying metadata.

We cannot work on this feature for now, but we would accept a PR to add the option. :)

LeFanch commented 9 months ago

Just to share, I've found a way to do that with piexif :

https://gist.github.com/LeFanch/3a4de05f59412ff1f2384bea04687e69

I've not checked if all fields are copied, but it keeps my camera model and GPS coordinates.

The idea is to get EXIF data before optimization then reinject them after. It's very fast.

flozz commented 9 months ago

Thank you, I will have a look the next time I work on this project :)

AhmedThahir commented 8 months ago

Any updates?