Skip to content

Commit c02c976

Browse files
committed
Updated readme and main entry point example
1 parent 86a97c1 commit c02c976

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,13 @@ use std::path::Path;
2424
fn main() -> Result<(), Box<dyn Error>> {
2525
let image_path = Path::new("tests/smiley.jpg");
2626

27-
// Reading IPTC metadata
27+
// Reading IPTC metadata from file
2828
let mut iptc = IPTC::read_from_path(&image_path)?;
2929

30+
// Alternatively, you can read from a buffer
31+
// let buffer = std::fs::read(&image_path)?;
32+
// let mut iptc = IPTC::read_from_buffer(&buffer)?;
33+
3034
// See all the tags in the image
3135
println!("IPTC: {:?}", iptc.get_all());
3236

@@ -46,6 +50,11 @@ fn main() -> Result<(), Box<dyn Error>> {
4650

4751
iptc.write_to_file(&image_path)?;
4852

53+
// Alternatively, you can write to a buffer
54+
// let buffer = std::fs::read(&image_path)?;
55+
// let updated_buffer = iptc.write_to_buffer(&buffer)?;
56+
// std::fs::write("output.jpg", updated_buffer)?;
57+
4958
Ok(())
5059
}
5160
```

src/lib.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
//! fn main() -> Result<(), Box<dyn Error>> {
1111
//! let image_path = Path::new("tests/smiley.jpg");
1212
//!
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)?;
1419
//!
1520
//! // See all the tags in the image
1621
//! println!("IPTC: {:?}", iptc.get_all());
@@ -19,6 +24,23 @@
1924
//! let keywords = iptc.get(IPTCTag::Keywords);
2025
//! println!("keywords: {}", keywords);
2126
//!
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+
//!
2244
//! Ok(())
2345
//! }
2446
//! ```

0 commit comments

Comments
 (0)