pub struct Client {
pub key: String,
}Fields
key: StringImplementations
sourceimpl Client
impl Client
pub fn new(key: String) -> Self
sourcepub fn from_file(&self, path: &str) -> Result<Source, TinifyException>
pub fn from_file(&self, path: &str) -> Result<Source, TinifyException>
Choose a file to compress.
Examples
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(())
}sourcepub fn from_buffer(&self, buffer: &[u8]) -> Result<Source, TinifyException>
pub fn from_buffer(&self, buffer: &[u8]) -> Result<Source, TinifyException>
Choose a buffer to compress.
Examples
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(())
}sourcepub fn from_url(&self, url: &str) -> Result<Source, TinifyException>
pub fn from_url(&self, url: &str) -> Result<Source, TinifyException>
Choose an url file to compress.
Examples
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(())
}Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl UnwindSafe for Client
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more