VipsBuffer

Trait VipsBuffer 

Source
pub trait VipsBuffer {
    // Required method
    fn thumbnail(&self, width: u32, height: u32) -> Result<VipsImage<'_>>;
}
Expand description

Extension trait for thumbnailing from a byte buffer

§Example

use vips::*;

fn main() -> Result<()> {
    let _instance = VipsInstance::new("app_test", true)?;
    let binding = std::fs::read("./examples/images/kodim01.png")?;
    let img_data: &[u8] = binding.as_slice();
    let thumbnail = img_data.thumbnail(100, 100)?;
    thumbnail.write_to_file("kodim01_thumb.png")?;
    Ok(())
}

Required Methods§

Source

fn thumbnail(&self, width: u32, height: u32) -> Result<VipsImage<'_>>

Implementations on Foreign Types§

Source§

impl VipsBuffer for &[u8]

Source§

fn thumbnail(&self, width: u32, height: u32) -> Result<VipsImage<'_>>

Create a thumbnail VipsImage from the byte buffer

§Arguments
  • width - The desired thumbnail width
  • height - The desired thumbnail height
§Errors

Returns an error if the thumbnail creation fails

§Example
use vips::*;

fn main() -> Result<()> {
    let _instance = VipsInstance::new("app_test", true)?;
    let binding = std::fs::read("./examples/images/kodim01.png")?;
    let img_data: &[u8] = binding.as_slice();
    let thumbnail = img_data.thumbnail(100, 100)?;
    thumbnail.write_to_file("kodim01_thumb.png")?;
    Ok(())
}
§Safety Note

The input byte slice must contain valid image data that libvips can decode. Providing invalid or corrupted data may lead to undefined behavior. Ensure that the data is properly validated before calling this method.

Implementors§