Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Danieroner/tinify-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

86 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 = "1.0.0"

Usage

use tinify::{Tinify, TinifyException};

fn main() -> Result<(), TinifyException> {
  let key = "tinify api key";
  let optimized = Tinify::new()
    .set_key(key)
    .get_client()?
    .from_file("./unoptimized.png")?
    .to_file("./optimized.png");
 
  Ok(())
}
  • Compress from an url file
use tinify::{Tinify, TinifyException};

fn main() -> Result<(), TinifyException> {
  let key = "tinify api key";
  let optimized = Tinify::new()
    .set_key(key)
    .get_client()?
    .from_url("https://tinypng.com/images/panda-happy.png")?
    .to_file("./optimized.png");
 
  Ok(())
}
  • Compress from a file buffer
use tinify::{Tinify, TinifyException};
use std::fs;

fn main() -> Result<(), TinifyException> {
  let key = "tinify api key";
  let bytes = fs::read("./unoptimized.png").unwrap();
  let buffer = Tinify::new()
    .set_key(key)
    .get_client()?
    .from_buffer(&bytes)?
    .to_buffer();
  
  let save = fs::write("./optimized.png", buffer).unwrap();
   
  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.

About

A Rust client for the Tinify API

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages