Tinify API client for Rust

Build Status crates.io

Rust client for the Tinify API, used for TinyPNG and TinyJPG. Tinify compresses your images intelligently. Read more at https://tinify.com.

Documentation

Go to the documentation for the HTTP client.

Status

In currently development.

There are still features of TinyPNG to implement.

To look at all the features of Tinify API: Documentation.

Getting Started

Install the API client with Cargo. Add this to Cargo.toml:

toml [dependencies] tinify-rs = "1.2.0"

Usage

fn main() -> Result<(), TinifyError> { let key = "tinify api key"; let tinify = Tinify::new().setkey(key); let client = tinify.getclient()?; let _ = client .fromfile("./unoptimized.jpg")? .tofile("./optimized.jpg")?;

Ok(()) } ```

fn main() -> Result<(), TinifyError> { let key = "tinify api key"; let tinify = Tinify::new().setkey(key); let client = tinify.getclient()?; let _ = client .fromurl("https://tinypng.com/images/panda-happy.png")? .tofile("./optimized.png")?;

Ok(()) } ```

fn main() -> Result<(), TinifyError> { let key = "tinify api key"; let tinify = Tinify::new().setkey(key); let client = tinify.getclient()?; let bytes = fs::read("./unoptimized.jpg")?; let _ = client .frombuffer(&bytes)? .tofile("./optimized.jpg")?;

Ok(()) } ```

fn get_client() -> Result { let key = "tinify api key"; let tinify = Tinify::new();

tinify .setkey(key) .getclient() }

fn main() -> Result<(), TinifyError> { let client = getclient()?; let _ = client .fromfile("./unoptimized.jpg")? .resize(Resize::new( Method::FIT, Some(400), Some(200)), )? .to_file("./resized.jpg")?;

Ok(()) } ```

fn main() -> Result<(), TinifyError> { let _ = Tinify::new() .setkey("api key") .getclient()? .fromfile("./tmpimage.jpg")? .convert(( Some(Type::PNG), None, None, ), None, )? .to_file("./converted.png");

Ok(()) } ```

fn main() -> Result<(), TinifyError> { let _ = Tinify::new() .setkey("api key") .getclient()? .fromurl("https://tinypng.com/images/panda-happy.png")? .convert(( Some(Type::JPEG), None, None, ), Some(Color("#FF5733")), )? .tofile("./converted.jpg");

Ok(()) } ```

Running tests

Create a .env file with a TiniPNG KEY

cargo test

Contribution

All contributions will be welcomed. Feel free to open any issues or pull requests.