~mort/coffeepaste

ref: b9f5ac1ec6061d264a74bd6c8d70c1854d491c05 coffeepaste/src/exif.rs -rw-r--r-- 946 bytes
b9f5ac1eMartin Dørum fix error in 400.html 10 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use log::{error};

use rexiv2;
use std::path::Path;

pub fn strip(dir: &str, name: &str) {
    let pathbuf = Path::new(dir).join(name);
    let meta = match rexiv2::Metadata::new_from_path(&pathbuf) {
        Err(err) => {
            error!("Failed to read exif data for {}: {}", pathbuf.to_string_lossy(), err);
            return;
        },
        Ok(meta) => meta,
    };

    if !meta.has_exif() && !meta.has_iptc() && !meta.has_exif() {
        return;
    }

    // I assume we don't need xmp or iptc
    meta.clear_xmp();
    meta.clear_iptc();

    // Only keep orientation from exif
    if meta.has_exif() {
        let orientation = meta.get_orientation();
        meta.clear_exif();
        if orientation != rexiv2::Orientation::Unspecified {
            meta.set_orientation(orientation);
        }
    }

    if let Err(err) = meta.save_to_file(&pathbuf) {
        error!("Failed to save exif: {}", err);
        return;
    }
}