Add set_option method.
This is useful for stuff like setting the loop option for a gif.
This commit is contained in:
@ -31,6 +31,18 @@ impl MagickWand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_option(&mut self, key: &str, value: &str) -> Result<(), &'static str> {
|
||||||
|
let c_key = CString::new(key).unwrap();
|
||||||
|
let c_value = CString::new(value).unwrap();
|
||||||
|
let result = unsafe {
|
||||||
|
bindings::MagickSetOption(self.wand, c_key.as_ptr(), c_value.as_ptr())
|
||||||
|
};
|
||||||
|
match result {
|
||||||
|
bindings::MagickTrue => Ok(()),
|
||||||
|
_ => Err("failed to set option"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn annotate_image(&mut self, drawing_wand: &DrawingWand, x: f64, y: f64, angle: f64, text: &str) -> Result<(), &'static str> {
|
pub fn annotate_image(&mut self, drawing_wand: &DrawingWand, x: f64, y: f64, angle: f64, text: &str) -> Result<(), &'static str> {
|
||||||
let c_string = try!(CString::new(text).map_err(|_| "could not convert to cstring"));
|
let c_string = try!(CString::new(text).map_err(|_| "could not convert to cstring"));
|
||||||
match unsafe { bindings::MagickAnnotateImage(self.wand, drawing_wand.wand, x, y, angle, c_string.as_ptr() as *const _) } {
|
match unsafe { bindings::MagickAnnotateImage(self.wand, drawing_wand.wand, x, y, angle, c_string.as_ptr() as *const _) } {
|
||||||
|
|||||||
15
tests/lib.rs
15
tests/lib.rs
@ -155,3 +155,18 @@ fn test_auto_orient() {
|
|||||||
assert!(wand.auto_orient());
|
assert!(wand.auto_orient());
|
||||||
assert_eq!(false, wand.requires_orientation());
|
assert_eq!(false, wand.requires_orientation());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_set_option() {
|
||||||
|
START.call_once(|| {
|
||||||
|
magick_wand_genesis();
|
||||||
|
});
|
||||||
|
let mut wand = MagickWand::new();
|
||||||
|
assert!(wand.read_image("tests/data/IMG_5745.JPG").is_ok());
|
||||||
|
// The jpeg:size option is just a hint.
|
||||||
|
wand.set_option("jpeg:size", "128x128").unwrap();
|
||||||
|
let blob = wand.write_image_blob("jpeg").unwrap();
|
||||||
|
assert!(wand.read_image_blob(&blob).is_ok());
|
||||||
|
assert_eq!(192, wand.get_image_width());
|
||||||
|
assert_eq!(144, wand.get_image_height());
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user