TechnikTobi / little_exif

A little library for reading and writing EXIF data in pure Rust.
Apache License 2.0
22 stars 5 forks source link

keeping the other metadata when doing write_to_vec #24

Closed mschnell1 closed 3 weeks ago

mschnell1 commented 1 month ago

currently I do

        let source_file_path = PathBuf::from(source_token.source.clone());
        let mut file_content = fs::read(&source_file_path)?;
        let file_extension = match get_file_type(&source_file_path) {
            Ok(x) => x,
            Err(_) => {
                println!("could not get EXIF extension from {}", source_token.source);
                return Ok(());  // skipping TIFF files for testing
            }
        };
        let mut metadata = Metadata::new_from_vec(&file_content, file_extension)?;
        metadata.set_tag(ExifTag::ImageDescription(source_token.token.clone()));
        let file_extension = get_file_type(&source_file_path).unwrap();
        metadata.write_to_vec(&mut file_content, file_extension)?;
        fs::write(&target_p, file_content)?;

(with the files that don't error) I do get a file that has the desired ImageDescription (String in source_token.token.) But all other metadata tags are lost. I'd like to keep them. What is the recommended way to do so ?

BTW it seems unnecessary to call get_file_type twice. That would be better if the FileExtension type would derive Clone and Copy.

TechnikTobi commented 1 month ago

Can you please provide an example with both the original and the output file?

mschnell1 commented 1 month ago

Can you please provide an example with both the original and the output file? Is the code I provided the way I am supposed to do the task described ?

mschnell1 commented 1 month ago

There also are some pictures that get no exif tag at all. I'll upload an example for both cases....

mschnell1 commented 1 month ago

I found that the Explorer "Details" does show the exif tags (those that it supports)

But the image managing software I use (ThumbsPlus) does not show any exif tags with the file 0130_2019_Stockholm_Weihegold_6)

So this might get complicated....

[Edit: Explorer seems to show the ImageDescripton, Thumbsplus does not show any Exif tags] no tags any more: source: www.bitvibe.de/Upload/2019_Stockholm_Weihegold_6.jpg target: www.bitvibe.de/Upload/0130_2019_Stockholm_Weihegold_6.jpg

[Edit: this seems to work] (only new tag): source: www.bitvibe.de/Upload/A0468323.JPG target: www.bitvibe.de/Upload/0010_A0468323.JPG

TechnikTobi commented 1 month ago

0130_2019_Stockholm_Weihegold_6.jpg does show EXIF data ...? Or am I misunderstanding something here? Bildschirmfoto 2024-10-10 um 12 30 07

TechnikTobi commented 1 month ago

Can you please provide an example with both the original and the output file?

Is the code I provided the way I am supposed to do the task described ?

Yes - see previous screenshot with your target file that does include all of that EXIF data

mschnell1 commented 1 month ago

Hmm. I'll do more research. Maybe ThumbsPlus has a problem or there is some weird incompatibility.

TechnikTobi commented 1 month ago

Could you please re-try this with the 0.6.0 beta and check if ThumbsPlus is still unable to read the tags after writing? Ideally with the exact same original example file you provided here?

mschnell1 commented 1 month ago

The beta constructs a file that is handled (maybe -> see below) correctly by Thumbsplus from my original file (from which the) uploaded file was constructed by a previous Version of Little_Exif. The original Exif Tags are isplayd. The beta does not issue an error message when reading the uploaded file. it co9nstructs a file that ThumbsPlus shows no Exif Tags of. None the original, not the one just written by Litte-Exif beta.

mschnell1 commented 1 month ago

Here I found something weird new. With the original file handled by Little Exif Explorer "Details" shows different strings for Titel ("Equestrian Sport") and Betreff ("Weihegold OLD, Dressage Top Ten, Stockholm, Dezember 2019"). Betreff being what Little_Exif wrote as ImageDescription. What ThumbsPlus shows as Exif Comment is "191130 Friends Arena Isabell Werth, GER and Weihegold Old won the Grand Prix Dressage. Photo: Roland Thunholm Code: 718 35" (with some line brakes included). Thumbsplus is supposed to show all Exif Tags in a file, but it does not at all show the new ImageDescription just written by Little_Exif. (Usually it shows this as Exif Comment which it transfers as Annotationinto it's database.) With the files I considered as "working" all three said Tag-Displays were the same. I'll re-upload the original file so you can test have Little_Exif write a new ImageDescription. Its the one I already did upload: -> www.bitvibe.de/Upload/2019_Stockholm_Weihegold_6.jpg

TechnikTobi commented 1 month ago

Sorry, I'm losing track of what is happening here.

1st comment:

The beta constructs a file that is handled (maybe -> see below) correctly by Thumbsplus from my original file

Let's call them ORIGINAL.JPG and BETA1.JPG

(from which the) uploaded file was constructed by a previous Version of Little_Exif.

So the uploaded file is not ORIGINAL.JPG but some file OLD.JPG that was constructed using a release prior to 0.6.0-beta1. Correct?

The original Exif Tags are isplayd.

What file? ORIGINAL.JPG? OLD.JPG? BETA1.JPG? What software? ThumbsPlus? little_exif_0.5.x? little_exif_0.6.0_beta1? Windows Explorer?

The beta does not issue an error message when reading the uploaded file.

Okay, but how is it of relevance that the beta is processing OLD.JPG correctly? ORIGINAL.JPG is what is of importance for initial processing by little_exif.

it co9nstructs a file that ThumbsPlus shows no Exif Tags of.

What is the base file? ORIGINAL.JPG or OLD.JPG?

2nd comment:

With the original file handled by Little Exif Explorer "Details" shows different strings for Titel ("Equestrian Sport") and Betreff ("Weihegold OLD, Dressage Top Ten, Stockholm, Dezember 2019"). Betreff being what Little_Exif wrote as ImageDescription. What ThumbsPlus shows as Exif Comment is "191130 Friends Arena Isabell Werth, GER and Weihegold Old won the Grand Prix Dressage. Photo: Roland Thunholm Code: 718 35" (with some line brakes included).

Using the file www.bitvibe.de/Upload/2019_Stockholm_Weihegold_6.jpg I get:

mschnell1 commented 1 month ago

With the original file handled by Little Exif Explorer "Details" shows different strings for Titel ("Equestrian Sport") and Betreff ("Weihegold OLD, Dressage Top Ten, Stockholm, Dezember 2019"). Betreff being what Little_Exif wrote as ImageDescription. What ThumbsPlus shows as Exif Comment is "191130 Friends Arena Isabell Werth, GER and Weihegold Old won the Grand Prix Dressage. Photo: Roland Thunholm Code: 718 35" (with some line brakes included).

Using the file www.bitvibe.de/Upload/2019_Stockholm_Weihegold_6.jpg I get:

* The `ImageDescription` (tag 0x010E) is "191130 Friends Arena
  Isabell Werth, GER and Weihegold Old won the Grand Prix Dressage.
  Photo: Roland Thunholm
  Code: 718 35�"

* However, this same string also appears a second time in the JPG's Photoshop Application Segment (which has _nothing_ to do with EXIF metadata). Can't tell yet which of the two gets displayed by ThumbsPlus.

* This same segment also holds the String "Equestrian Sport". This also appears a second time as part of the XMP data.

* The string "Weihegold OLD, Dressage Top Ten, Stockholm, Dezember 2019" is nowhere to be found in the file.

That is exactly what I intended. The file uploaded is the original I have in the stock. It's Exif data don't really matter but should be preserved (at least for now) sauf the ImageDescription The goal of the program is to have the file show a new ImageDescription Now this supposedly is exactly what Litte_Exif beta does for this file. (while v0.5.1 deleted all old Exif) Due to the weirdness of EXIF, the way I can look at the result is not safe. Explorer "details" provides Titel and Betreffwhich both sometimes show the ImageDescription but not always. Here it shows it as Betreffbut something old as Titel. ThumbsPlus provides Comments, which mostly shows ImageDescription, but not with the result I get when having Little_Exif set the ImageDescription in the file.

I think you can easily make Little_Exif set any ImageDescription in this file and take a look at the result, hence I did not upload the resulting file.

Sorry for confusion ... (I don't have any tools that show the would be "correct" result). I maybe could use "exif-tool" but is that more trust-worthy ?

TechnikTobi commented 3 weeks ago

What is the status on this issue? I've lost overview of what was the exact problem here. Is this perhaps solved with the clear_app13_segment function in beta5?

mschnell1 commented 3 weeks ago

Seems fine with Beta.5