Skip to content

Problem to copy exif data of image made with Canon EOS 650D #2

@chriamue

Description

@chriamue

While trying to integrate img-parts into my project I observed a problem processing images of one camera.
In the following example I take the image
IMG_0818
extract the exif data and save it to large.jpg.

I observe the tool, which is based on libexif

exif -v
0.6.21

reports the exif data is corrupt.

exif large.jpg
Corrupt data
The data provided does not follow the specification.
ExifLoader: The data supplied does not seem to contain EXIF data.

Also many other programs like filebrowser nemo can not view the exif data.
The tool exiftool still can read the exif data.

exiftool large.jpg
ExifTool Version Number         : 11.88
File Name                       : large.jpg
Directory                       : .
File Size                       : 5.9 MB
File Modification Date/Time     : 2021:05:25 06:57:57+02:00
File Access Date/Time           : 2021:05:25 06:57:59+02:00
File Inode Change Date/Time     : 2021:05:25 06:57:57+02:00
File Permissions                : rw-rw-r--
File Type                       : JPEG
File Type Extension             : jpg
MIME Type                       : image/jpeg
Rating                          : 0
Image Width                     : 5184
Image Height                    : 3456
...

If I use the image https://github.com/paolobarbolini/img-parts/blob/main/tests/images/P1133897_sRGB.jpg as
source for the image data or the other way around as source for the exif data,
the resulting images are both readable with exif.

Here is the code with Cargo.toml dependencies: img-parts = { git = "https://github.com/paolobarbolini/img-parts"}

#[cfg(test)]
mod tests {
    use img_parts::jpeg::Jpeg;
    use img_parts::{ImageEXIF, ImageICC};

    #[test]
    fn large_jpg() {
        replace_exif(
            "IMG_0818.JPG".into(),
            "IMG_0818.JPG".into(),
            "large.jpg".into(),
        );
    }

    #[test]
    fn normal_large_jpg() {
        replace_exif(
            "P1133897_sRGB.jpg".into(),
            "IMG_3911.JPG".into(),
            "normal_large.jpg".into(),
        );
    }

    #[test]
    fn large_normal_jpg() {
        replace_exif(
            "IMG_3911.JPG".into(),
            "P1133897_sRGB.jpg".into(),
            "large_normal.jpg".into(),
        );
    }

    fn replace_exif(image: String, exif_image: String, out_file: String) {
        let buf = std::fs::read(image).expect("image read");
        let buf_exif = std::fs::read(exif_image).expect("image read");
        let (iccp, exif) = img_parts::DynImage::from_bytes(buf_exif.clone().into())
            .expect("image loaded")
            .map_or((None, None), |dimg| (dimg.icc_profile(), dimg.exif()));
        let mut out_file = std::fs::File::create(out_file).expect("create output file");

        let mut jpeg = Jpeg::from_bytes(buf.into()).unwrap();
        jpeg.set_icc_profile(iccp);
        jpeg.set_exif(Some(exif.unwrap()));
        jpeg.encoder().write_to(&mut out_file).unwrap();
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions