1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use ::ffi;
use VipsImage;
use std::os::raw::c_void;
use std::os::raw::c_int;
use std::os::raw::c_char;
use std::ptr::null;
use std::error::Error;
pub trait VipsBuffer {
fn thumbnail(&self, width:u32, height:u32) -> Result<VipsImage, Box<Error>>;
}
impl<'a> VipsBuffer for &'a [u8] {
fn thumbnail(&self, width:u32, height:u32) -> Result<VipsImage, Box<Error>> {
unsafe {
let mut out = VipsImage::new_memory()?;
ffi::vips_thumbnail_buffer(self.as_ptr() as *mut c_void, self.len(), &mut out.c, width as c_int, "height\0".as_ptr(), height as c_int, "size\0".as_ptr(), ffi::VipsSize::VIPS_SIZE_FORCE, null() as *const c_char);
Ok(out)
}
}
}