Rust client for the Tinify API, 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.
Install the API client with Cargo. Add this to Cargo.toml
:
toml
[dependencies]
tinify-rs = "1.0.0"
About key
Get an API key from https://tinypng.com/developers
Compress from a file ```rust use tinify::{Tinify, TinifyException};
fn main() -> Result<(), TinifyException> { let key = "tinify api key"; let optimized = Tinify::new() .setkey(key) .getclient()? .fromfile("./unoptimized.png")? .tofile("./optimized.png");
Ok(()) } ```
fn main() -> Result<(), TinifyException> { let key = "tinify api key"; let optimized = Tinify::new() .setkey(key) .getclient()? .fromurl("https://tinypng.com/images/panda-happy.png")? .tofile("./optimized.png");
Ok(()) } ```
fn main() -> Result<(), TinifyException> { let key = "tinify api key"; let bytes = fs::read("./unoptimized.png").unwrap(); let buffer = Tinify::new() .setkey(key) .getclient()? .frombuffer(&bytes)? .tobuffer();
let save = fs::write("./optimized.png", buffer).unwrap();
Ok(()) } ```
Create a .env file with a TiniPNG KEY
cargo test
All contributions will be welcomed. Feel free to open any issues or pull requests.