pub struct TinifyResult { /* private fields */ }Expand description
Represents the result of Tinify API operations
TinifyResult contains response data and metadata after API operations,
and can be used to retrieve processed image data, metadata information, etc.
Implementations§
Source§impl TinifyResult
impl TinifyResult
Sourcepub async fn to_buffer(&mut self) -> Result<Vec<u8>>
pub async fn to_buffer(&mut self) -> Result<Vec<u8>>
Get image data to memory buffer
Read the image data from the response into a byte array. Note: This method consumes the response data and can only be called once.
§Examples
use tinify::Tinify;
let client = Tinify::new("your-api-key".to_string())?;
let source = client.source_from_file("input.png").await?;
let mut result = source.resize(Default::default()).await?;
let image_data = result.to_buffer().await?;
println!("Image size: {} bytes", image_data.len());Sourcepub async fn to_file<P: AsRef<Path>>(&mut self, path: P) -> Result<()>
pub async fn to_file<P: AsRef<Path>>(&mut self, path: P) -> Result<()>
Save image to local file
Save the image data from the response to the specified local file path. Note: This method consumes the response data and can only be called once.
§Arguments
path- Local file path to save the image
§Examples
use tinify::Tinify;
let client = Tinify::new("your-api-key".to_string())?;
let source = client.source_from_file("input.png").await?;
let mut result = source.resize(Default::default()).await?;
result.to_file("output.png").await?;
println!("Image saved to output.png");Sourcepub fn compression_count(&self) -> Option<u32>
pub fn compression_count(&self) -> Option<u32>
Get compression count
Returns the compression count statistics for the current API key this month.
§Returns
Returns Some(count) if the response header contains compression count information, otherwise returns None.
Sourcepub fn image_width(&self) -> Option<u32>
pub fn image_width(&self) -> Option<u32>
Get image width
Returns the width (in pixels) of the processed image.
§Returns
Returns Some(width) if the response header contains image width information, otherwise returns None.
Sourcepub fn image_height(&self) -> Option<u32>
pub fn image_height(&self) -> Option<u32>
Get image height
Returns the height (in pixels) of the processed image.
§Returns
Returns Some(height) if the response header contains image height information, otherwise returns None.
Sourcepub fn content_type(&self) -> Option<String>
pub fn content_type(&self) -> Option<String>
Get content type
Returns the MIME type of the response (such as “image/jpeg”, “image/png”, etc.).
§Returns
Returns Some(content_type) if the response header contains content type information, otherwise returns None.
Sourcepub fn content_length(&self) -> Option<u64>
pub fn content_length(&self) -> Option<u64>
Get content length
Returns the byte size of the response content.
§Returns
Returns Some(length) if the response header contains content length information, otherwise returns None.