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.3.0"Using async client
[dependencies]
tinify-rs = { version = "1.3.0", features = ["async"] }-
About key
Get an API key from https://tinypng.com/developers
-
Compress from a file
use tinify::Tinify;
use tinify::TinifyError;
fn main() -> Result<(), TinifyError> {
let key = "tinify api key";
let tinify = Tinify::new().set_key(key);
let client = tinify.get_client()?;
let _ = client
.from_file("./unoptimized.jpg")?
.to_file("./optimized.jpg")?;
Ok(())
}- Compress from a file async
use tinify::async_bin::Tinify as AsyncTinify;
use tinify::error::TinifyError;
#[tokio::main]
async fn main() -> Result<(), TinifyError> {
let key = "tinify api key";
let tinify = AsyncTinify::new().set_key(key);
let client = tinify.get_async_client()?;
client
.from_file("./unoptimized.jpg")
.await?
.to_file("./optimized.jpg")?;
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.