Crates.io | tinify-rs |
lib.rs | tinify-rs |
version | 1.4.1 |
source | src |
created_at | 2021-06-20 00:24:03.045197 |
updated_at | 2024-05-01 23:23:28.290395 |
description | A Rust client for the Tinify API |
homepage | https://github.com/Danieroner/tinify-rs |
repository | https://github.com/Danieroner/tinify-rs |
max_upload_size | |
id | 412250 |
size | 181,272 |
Tinify API Client for the Rust Programming Language, used for TinyPNG and TinyJPG. Tinify compresses your images intelligently. Read more at https://tinify.com.
Go to the documentation for the HTTP client.
In currently development.
There are still features of TinyPNG to implement.
To look at all the features of Tinify API: Documentation.
Compressing images
Resizing images
Converting images
Preserving metadata
Saving to Amazon S3
Saving to Google Cloud Storage
Implement an async non-blocking Client
Install the API client with Cargo. Add this to Cargo.toml
:
[dependencies]
tinify-rs = "1.4.1"
Using async client
[dependencies]
tinify-rs = { version = "1.4.1", features = ["async"] }
About key
Get an API key from https://tinypng.com/developers
Compress from a file
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(())
}
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 compressed = tinify
.get_async_client()?
.from_file("./unoptimized.jpg").await?
.to_file(output).await;
if let Err(error) = compressed {
match error {
TinifyError::ClientError { ref upstream } => {
println!("Error: {} message: {}", upstream.error, upstream.message);
}
_ => println!("{:?}", error),
}
}
Ok(())
}
Create a .env file with a TiniPNG KEY
cargo test --features async
All contributions will be welcomed. Feel free to open any issues or pull requests.