|
10 | 10 | //! fn main() -> Result<(), Box<dyn Error>> {
|
11 | 11 | //! let image_path = Path::new("tests/smiley.jpg");
|
12 | 12 | //!
|
13 |
| -//! let iptc = IPTC::read_from_path(&image_path)?; |
| 13 | +//! // Reading IPTC metadata from file |
| 14 | +//! let mut iptc = IPTC::read_from_path(&image_path)?; |
| 15 | +//! |
| 16 | +//! // Alternatively, you can read from a buffer |
| 17 | +//! // let buffer = std::fs::read(&image_path)?; |
| 18 | +//! // let mut iptc = IPTC::read_from_buffer(&buffer)?; |
14 | 19 | //!
|
15 | 20 | //! // See all the tags in the image
|
16 | 21 | //! println!("IPTC: {:?}", iptc.get_all());
|
|
19 | 24 | //! let keywords = iptc.get(IPTCTag::Keywords);
|
20 | 25 | //! println!("keywords: {}", keywords);
|
21 | 26 | //!
|
| 27 | +//! // Writing new metadata |
| 28 | +//! // For repeatable fields like Keywords, you can add multiple values |
| 29 | +//! let keywords = vec!["rust", "metadata", "iptc"]; |
| 30 | +//! for keyword in keywords { |
| 31 | +//! iptc.set_tag(IPTCTag::Keywords, keyword); |
| 32 | +//! } |
| 33 | +//! |
| 34 | +//! // For single-value fields, just set them directly |
| 35 | +//! iptc.set_tag(IPTCTag::City, "Oslo"); |
| 36 | +//! |
| 37 | +//! iptc.write_to_file(&image_path)?; |
| 38 | +//! |
| 39 | +//! // Alternatively, you can write to a buffer |
| 40 | +//! // let buffer = std::fs::read(&image_path)?; |
| 41 | +//! // let updated_buffer = iptc.write_to_buffer(&buffer)?; |
| 42 | +//! // std::fs::write("output.jpg", updated_buffer)?; |
| 43 | +//! |
22 | 44 | //! Ok(())
|
23 | 45 | //! }
|
24 | 46 | //! ```
|
|
0 commit comments