File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments