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

Plans to add support for writing tags? #1

Open
Ortham opened this issue Jun 20, 2017 · 15 comments
Open

Plans to add support for writing tags? #1

Ortham opened this issue Jun 20, 2017 · 15 comments

Comments

@Ortham
Copy link

Ortham commented Jun 20, 2017

I forked rexif to add support for writing GPS tags to it, but upstream hasn't been touched in over a year, the only tests it has are the ones I've added, and I've had to spend time improving the implementation. On the other hand, this library seems to have come on leaps and bounds since I last saw it, and I'm wondering if I should maybe switch my efforts.

Do you plan on adding write support, and if not, would you be interested in a pull request adding it?

@kamadak
Copy link
Owner

kamadak commented Jun 20, 2017

It depends on your use case.

If you are writing Exif data from scratch, it is easy. I will add some support. (Actually, I have scribbled a pre-pre-pre-alpha-quality encoder before, so I need to salvage it...)

If you are modifying existing data, the situation becomes tricky. The problem is that some opaque fields (e.g., MakerNote) may have non-relative offsets in them and they are broken if their positions are changed, unless we deep-inspect and rewrite them. A well-known heuristic is to keep the absolute positions of such fields while reencoding the Exif structure, but it is bothersome. 😫

If you only add GPS tags, the easiest way might be to implement a special logic only for that.

@Ortham
Copy link
Author

Ortham commented Jun 20, 2017

It would be modifying existing data, I didn't think about non-relative offsets... My use-case only requires writing GPS tags, and since they sit separately, special logic would probably be best for them.

@kamadak
Copy link
Owner

kamadak commented Jul 16, 2017

I have checked in the experimental support for the former use case.
For the latter, I will think about it but it will take some time, so I am also welcome for pull requests.

@Ortham
Copy link
Author

Ortham commented Jul 16, 2017

Thanks, I'll check it out when I get the chance. 👍

@bosschaert
Copy link

This is a very old issue. I'm just wondering if there are any plans to implement it?

I'm just looking to write date/time exif information in case it's missing...

@Ortham
Copy link
Author

Ortham commented Jan 11, 2020

I abandoned the project that involved needing to write EXIF data before I made much progress (and I was only looking at GPS tags anyway).

@bosschaert
Copy link

It seems like the https://github.com/liamstask/imagemeta-rs project has some support for it, but that one looks abandoned as well...

@kamadak
Copy link
Owner

kamadak commented Jan 13, 2020

The following steps mostly work, except that MakerNote of some makes will be broken. Do no do this unless relocation of MakerNote is known to be safe with your camera.

  1. Parse the file with Reader.
  2. Create an Writer instance.
  3. Iterate over Reader::fields and feed them into Writer::push_field, with filtering out the tags you want to update.
  4. Prepare the new contents of tags you want to update/add, and feed them into Writer::push_field.
  5. Get the thumbnail image from Reader (see get_jpeg and get_strips functions in tests/rwrcmp.rs) and feed it into Writer::set_jpeg or Writer::set_strips.
  6. Serialize the Exif data with Writer::write.
  7. Replace the old Exif data in JPEG with the new one.

Missing pieces are:

  • Step 7 is not (and will never be) supported by this library, so use some JPEG library.
  • Relocation-unsafe MakerNotes should be detected and rewriten if necessary. This may be supported in the future, but there is no concrete plan.

@bosschaert
Copy link

Thanks @kamadak for the details. On point 7, do you know a JPEG library that would be able to do this? I looked around and found https://github.com/image-rs/image but I could not find a way using that library to set the EXIF data...

@kamadak
Copy link
Owner

kamadak commented Jan 20, 2020

I have thought there must be some, but I searched on the web to find nothing in Rust.

Enhancing the encoder of the image library you mentioned seems very easy.
Just add an APP1 segment with Exif marker + Exif data around here: https://github.com/image-rs/image/blob/cf0cb54ef4d12526091e5c61768da0624615b446/src/jpeg/encoder.rs#L384-L385.
On the other hand, I did not find a functionality in that library to embed metadata without decoding/encoding cycle, which we want to avoid because the image quality may degrade.

@NelDav
Copy link

NelDav commented Aug 4, 2020

Thanks @kamadak for the details. On point 7, do you know a JPEG library that would be able to do this? I looked around and found https://github.com/image-rs/image but I could not find a way using that library to set the EXIF data...

I think you search something like img-parts

@paolobarbolini
Copy link

paolobarbolini commented Aug 4, 2020

img-parts author here. Thanks @NelDav for mentioning my crate.

As you said img-parts can be used to read and write raw EXIF data to images. It currently supports JPEG, PNG and WEBP, with more formats to come in the future. You can use this crate to generate the raw data and have it written to the file through my crate, as shown in the example

@sophie-h
Copy link

Thanks for those detailed instructions on how to update EXIF data!

For some images, I got the exact same binary size for the rewritten raw data. For others, I didn't. Is this expected or does that mean I'm missing some data in the new EXIF?

It also looks like the order of fields changes. Is that correct and if so, is that avoidable?

5. Get the thumbnail image from Reader (see get_jpeg and get_strips functions in tests/rwrcmp.rs) and feed it into Writer::set_jpeg or Writer::set_strips.

Would you accept a PR adding those functions to either experimental or Reader?

@mschnell1
Copy link

mschnell1 commented Sep 15, 2024

* Step 7 is not (and will never be) supported by this library, so use some JPEG library.

Why is this ?
It seems writing some exif information to a file already works
it seems that the only step missing is to extract the binary jpeg image data from the file and use set_jpeg() to file.

It would be just great of this would be possible. even if currently only for standard jpeg picture files.

BTW.: what would JPG files without image be useful for ?

BTW/2:

Step 5 "Get the thumbnail image from Reader (see get_jpeg and get_strips functions in tests/rwrcmp.rs) and feed it into Writer::set_jpeg or Writer::set_strips."

I tried to test get_jpeg but can't find out what the ifd_num is supposed to be. But, anyway, the thumbnail is not in my scope right now.

BTW/3:
If writing JPG files is not supported here, what crate might be able to just add or replace an EXIF field in a jpg file ? (Here I just need ImageDescription.)

@mschnell1
Copy link

mschnell1 commented Sep 15, 2024

Here -> image-rs/image#1045 on on Nov 23, 2020, you write it already should work ????
Thanks for any comments !

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

7 participants