Skip to content

Commit da0f27f

Browse files
committed
Add example convert program
1 parent f686d89 commit da0f27f

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

examples/convert.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//! An example of opening an image.
2+
extern crate image;
3+
extern crate image_extras;
4+
5+
use std::env;
6+
use std::error::Error;
7+
use std::path::Path;
8+
9+
fn main() -> Result<(), Box<dyn Error>> {
10+
image_extras::register();
11+
12+
let (from, into) = if env::args_os().count() == 3 {
13+
(
14+
env::args_os().nth(1).unwrap(),
15+
env::args_os().nth(2).unwrap(),
16+
)
17+
} else {
18+
println!("Please enter a from and into path.");
19+
std::process::exit(1);
20+
};
21+
22+
// Use the open function to load an image from a Path.
23+
// ```open``` returns a dynamic image.
24+
let im = image::open(Path::new(&from)).unwrap();
25+
// Write the contents of this image using extension guessing.
26+
im.save(Path::new(&into)).unwrap();
27+
Ok(())
28+
}

0 commit comments

Comments
 (0)