-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from Danieroner/overall-improvement
Overall improvement
- Loading branch information
Showing
18 changed files
with
868 additions
and
878 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use tinify::error::TinifyError; | ||
use tinify::transform::Transform; | ||
use tinify::async_bin::Tinify; | ||
use tinify::convert::Convert; | ||
use tinify::convert::Type; | ||
use std::path::Path; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), TinifyError> { | ||
let key = "api key"; | ||
let convert = Convert { | ||
r#type: vec![Type::Jpeg], | ||
}; | ||
let transform = Transform { | ||
background: "#800020".to_string(), | ||
}; | ||
let output = Path::new("./optimized.jpg"); | ||
let tinify = Tinify::new().set_key(key); | ||
let optimized = tinify | ||
.get_async_client()? | ||
.from_url("https://tinypng.com/images/panda-happy.png").await? | ||
.convert(convert)? | ||
.transform(transform)? | ||
.to_file(output).await; | ||
|
||
if let Err(error) = optimized { | ||
match error { | ||
TinifyError::ClientError { ref upstream } => { | ||
println!("Error: {} message: {}", upstream.error, upstream.message); | ||
} | ||
_ => println!("{:?}", error), | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use tinify::error::TinifyError; | ||
use tinify::async_bin::Tinify; | ||
use std::path::Path; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), TinifyError> { | ||
let key = "api key"; | ||
let output = Path::new("./optimized.jpg"); | ||
let tinify = Tinify::new().set_key(key); | ||
let optimized = tinify | ||
.get_async_client()? | ||
.from_file("./unoptimized.jpg").await? | ||
.to_file(output).await; | ||
|
||
if let Err(error) = optimized { | ||
match error { | ||
TinifyError::ClientError { ref upstream } => { | ||
println!("Error: {} message: {}", upstream.error, upstream.message); | ||
} | ||
_ => println!("{:?}", error), | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use tinify::error::TinifyError; | ||
use tinify::async_bin::Tinify; | ||
use tinify::resize::Resize; | ||
use tinify::resize::Method; | ||
use std::path::Path; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), TinifyError> { | ||
let key = "api key"; | ||
let output = Path::new("./optimized.jpg"); | ||
let resize = Resize { | ||
method: Method::Fit, | ||
width: Some(150), | ||
height: Some(100), | ||
}; | ||
let tinify = Tinify::new().set_key(key); | ||
let optimized = tinify | ||
.get_async_client()? | ||
.from_file("./unoptimized.jpg").await? | ||
.resize(resize)? | ||
.to_file(output).await; | ||
|
||
if let Err(error) = optimized { | ||
match error { | ||
TinifyError::ClientError { ref upstream } => { | ||
println!("Error: {} message: {}", upstream.error, upstream.message); | ||
} | ||
_ => println!("{:?}", error), | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use tinify::error::TinifyError; | ||
use tinify::transform::Transform; | ||
use tinify::convert::Convert; | ||
use tinify::convert::Type; | ||
use tinify::sync::Tinify; | ||
use std::path::Path; | ||
|
||
fn main() -> Result<(), TinifyError> { | ||
let key = "api key"; | ||
let convert = Convert { | ||
r#type: vec![Type::Jpeg], | ||
}; | ||
let transform = Transform { | ||
background: "#800020".to_string(), | ||
}; | ||
let output = Path::new("./optimized.jpg"); | ||
let tinify = Tinify::new().set_key(key); | ||
let optimized = tinify | ||
.get_client()? | ||
.from_url("https://tinypng.com/images/panda-happy.png")? | ||
.convert(convert)? | ||
.transform(transform)? | ||
.to_file(output); | ||
|
||
if let Err(error) = optimized { | ||
match error { | ||
TinifyError::ClientError { ref upstream } => { | ||
println!("Error: {} message: {}", upstream.error, upstream.message); | ||
} | ||
_ => println!("{:?}", error), | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use tinify::error::TinifyError; | ||
use tinify::sync::Tinify; | ||
use std::path::Path; | ||
|
||
fn main() -> Result<(), TinifyError> { | ||
let key = "api key"; | ||
let output = Path::new("./optimized.jpg"); | ||
let tinify = Tinify::new().set_key(key); | ||
let optimized = tinify | ||
.get_client()? | ||
.from_file("./unoptimized.jpg")? | ||
.to_file(output); | ||
|
||
if let Err(error) = optimized { | ||
match error { | ||
TinifyError::ClientError { ref upstream } => { | ||
println!("Error: {} message: {}", upstream.error, upstream.message); | ||
} | ||
_ => println!("{:?}", error), | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use tinify::error::TinifyError; | ||
use tinify::resize::Method; | ||
use tinify::resize::Resize; | ||
use tinify::sync::Tinify; | ||
use std::path::Path; | ||
|
||
fn main() -> Result<(), TinifyError> { | ||
let key = "api key"; | ||
let resize = Resize { | ||
method: Method::Fit, | ||
width: Some(150), | ||
height: Some(100), | ||
}; | ||
let output = Path::new("./optimized.jpg"); | ||
let tinify = Tinify::new().set_key(key); | ||
let optimized = tinify | ||
.get_client()? | ||
.from_file("./unoptimized.jpg")? | ||
.resize(resize)? | ||
.to_file(output); | ||
|
||
if let Err(error) = optimized { | ||
match error { | ||
TinifyError::ClientError { ref upstream } => { | ||
println!("Error: {} message: {}", upstream.error, upstream.message); | ||
} | ||
_ => println!("{:?}", error), | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |
Oops, something went wrong.