Skip to content

Instantly share code, notes, and snippets.

@jgould22
Last active February 10, 2021 15:54
Show Gist options
  • Save jgould22/8e3a09497e5821d9dcd0575d9c830be0 to your computer and use it in GitHub Desktop.
Save jgould22/8e3a09497e5821d9dcd0575d9c830be0 to your computer and use it in GitHub Desktop.
#[cfg(test)]
mod tests {
use std::io::Read;
use libvips::{ops as VipsOps, VipsApp, VipsImage};
fn init_vips() -> VipsApp {
let image_processor = VipsApp::new("libvips-test", false).expect("Failed to initialize libvips");
image_processor.concurrency_set(4);
image_processor
}
fn get_file_as_byte_vec(filename: &String) -> Vec<u8> {
let mut f = std::fs::File::open(&filename).expect("no file found");
let metadata = std::fs::metadata(&filename).expect("unable to read metadata");
let mut buffer = vec![0; metadata.len() as usize];
f.read(&mut buffer).expect("buffer overflow");
buffer
}
#[test]
fn thumnail_error() {
let vips_app = init_vips();
let image_file = get_file_as_byte_vec(&"tests/images/resize_fail.jpg".to_string());
let vips_image = VipsImage::new_from_buffer(&image_file, "[autorotate]").unwrap();
let options = VipsOps::ThumbnailImageOptions {
height:400,
..VipsOps::ThumbnailImageOptions::default()
};
let this_fails = match VipsOps::thumbnail_image_with_opts(&vips_image, 300, &options) {
Ok(image) => Ok(image),
Err(error)=> {
dbg!(&error);
dbg!( vips_app.error_buffer().unwrap());
Err(error)
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment