Add get_image_property() to retrieve properties

cargo test passes
This commit is contained in:
Nathan Fiedler
2016-01-02 14:31:20 -08:00
parent 6ca185df19
commit 19377db422
5 changed files with 45 additions and 13 deletions

View File

@ -31,7 +31,7 @@
extern crate libc;
use std::ffi::CString;
use std::ffi::{CStr, CString};
use std::ptr;
use libc::{c_uint, c_double, c_void};
use filters::FilterType;
@ -98,6 +98,27 @@ impl MagickWand {
}
}
/// Retrieve the named image property value.
pub fn get_image_property(&self, name: &str) -> Result<&str, &'static str> {
let c_name = CString::new(name).unwrap();
let result = unsafe {
bindings::MagickGetImageProperty(self.wand, c_name.as_ptr())
};
let value = if result.is_null() {
Err("missing property")
} else {
let cstr = unsafe { CStr::from_ptr(result) };
match cstr.to_str() {
Ok(v) => Ok(v),
Err(_) => Err("invalid value")
}
};
unsafe {
bindings::MagickRelinquishMemory(result as *mut c_void);
}
value
}
/// Resize the image to the specified width and height, using the
/// specified filter type with the specified blur / sharpness factor.
///