caemor / tinify-rs

A Rust client for the Tinify API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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:

[dependencies]
tinify-rs = "0.2.0"

Usage

use tinify_rs::tinify;

fn main() {
  tinify::set_key("tinify api key");

  let source = tinify::from_file("./unoptimized.png");
  let compress = source.to_file("./optimized.png");
}
  • Compress from an url file
use tinify_rs::tinify;

fn main() {
  tinify::set_key("tinify api key");

  let source = tinify::from_url("https://tinypng.com/images/panda-happy.png");
  let compress = source.to_file("./optimized.png");
}
  • Compress from a file buffer
use tinify_rs::tinify;
use std::fs;

fn main() {}
  tinify::set_key("tinify api key");

  let bytes = fs::read("./unoptimized.png").unwrap();
  let buffer = tinify::from_buffer(&bytes).to_buffer();
  let save = fs::write("./optimized.png", buffer);
}

Running tests

cargo test

Contribution

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

About

A Rust client for the Tinify API

License:MIT License


Languages

Language:Rust 100.0%