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

Unable to read/write Exif metadata #86

Open
Disty0 opened this issue Nov 30, 2024 · 3 comments
Open

Unable to read/write Exif metadata #86

Disty0 opened this issue Nov 30, 2024 · 3 comments
Labels
enhancement New feature or request Rust Something about Rust side bindings upstream Issue related to upstream jpegxl-rs support

Comments

@Disty0
Copy link

Disty0 commented Nov 30, 2024

For reference, i am currently trying to implement JPEG XL support on a stable diffusion webui: vladmandic/automatic#3600
But i am unable to save and read exif metadata.

The line for generating the exif metadata:

exif = piexif.dump({ "Exif": { piexif.ExifIFD.UserComment: piexif.helper.UserComment.dump(exifinfo, encoding="unicode") } })

Added a print to this plugin's save function to see if it gets the exif metadata like this:

And it definitely gets the exif metadata so i am guessing this issue is on the rust backend:

Saved images has "something" as exif in them:

But nothing is able to read the exif metadata in the saved images:

I also have JXL images that has valid exif metadata in them (converted from jpg to jxl with imagemagick) but plugin is still unable to read the exif metadata.

@Isotr0py
Copy link
Owner

Isotr0py commented Dec 1, 2024

But nothing is able to read the exif metadata in the saved images.

Oh, that's because I set compress=True by default when encoding jxl image with metadata. However, many software (including exiftool and exiv2) can't recognize the compressed exif data. I have opened #87 to make it optional and disabled by default.

I also have JXL images that has valid exif metadata in them (converted from jpg to jxl with imagemagick) but plugin is still unable to read the exif metadata.

This plugin can't decode jxl images with exif data directly, because upstream jpegxl-rs doesn't have high-level API for this.

However, if a jxl image is created from jpeg reconstruction, the exif metadata should be handled correctly, because we will reconstruct jxl to jpeg in this plugin instead of directly decoding, which means we will return an JPEG PIL instance. So I guess the jpg->jxl convert in imagemagick is using direct encoding instead of lossless jpeg reconstruction.

BTW, if you use the official cjxl tool provided by libjxl to convert jxl from jpg, this plugin should be able to read the image with exif metadata. (This is also how I create sample jxl image with metadata for test)

@Isotr0py
Copy link
Owner

Isotr0py commented Dec 1, 2024

BTW, you can try to use the pre-release wheels from main branch: https://github.com/Isotr0py/pillow-jpegxl-plugin/releases/tag/exif-dev. These wheels should be able to encode image with exif metadata compatiable with exiv2 and exiftool.

@Disty0
Copy link
Author

Disty0 commented Dec 1, 2024

BTW, you can try to use the pre-release wheels from main branch: https://github.com/Isotr0py/pillow-jpegxl-plugin/releases/tag/exif-dev. These wheels should be able to encode image with exif metadata compatiable with exiv2 and exiftool.

Pre-release wheels fixed the metadata saving:

So I guess the jpg->jxl convert in imagemagick is using direct encoding instead of lossless jpeg reconstruction.

That is true. imagemagick still treats it as a png with -quality 100 instead of using jpeg reconstruction.

This plugin can't decode jxl images with exif data directly, because upstream jpegxl-rs doesn't have high-level API for this.

Saving is working with the pre-release wheels, so only this upstream issue remains right now.

@Isotr0py Isotr0py added enhancement New feature or request Rust Something about Rust side bindings upstream Issue related to upstream jpegxl-rs support labels Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Rust Something about Rust side bindings upstream Issue related to upstream jpegxl-rs support
Projects
None yet
Development

No branches or pull requests

2 participants