Binding for set_background_color

This commit is contained in:
Magic Len 2019-05-29 15:03:17 +08:00
parent 122f144ecb
commit 089e6fcb90
3 changed files with 28 additions and 0 deletions

View file

@ -437,6 +437,15 @@ impl MagickWand {
}
}
/// Set the background color.
pub fn set_background_color(&self, pixel_wand: &PixelWand) -> Result<(), &'static str> {
match unsafe { bindings::MagickSetBackgroundColor(self.wand, pixel_wand.wand) } {
bindings::MagickBooleanType_MagickTrue => Ok(()),
_ => Err("SetBackgroundColor returned false"),
}
}
/// Set the image background color.
pub fn set_image_background_color(&self, pixel_wand: &PixelWand) -> Result<(), &'static str> {
match unsafe { bindings::MagickSetImageBackgroundColor(self.wand, pixel_wand.wand) } {

2
tests/data/rust.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 7.5 KiB

View file

@ -303,3 +303,20 @@ fn test_set_image_background_color() {
assert_eq!(0u8, blob[1]);
assert_eq!(255u8, blob[2]);
}
#[test]
fn test_set_background_color() {
START.call_once(|| {
magick_wand_genesis();
});
let wand = MagickWand::new();
let mut pw = PixelWand::new();
pw.set_color("none").unwrap();
wand.set_background_color(&pw).unwrap();
assert!(wand.read_image("tests/data/rust.svg").is_ok());
let blob = wand.write_image_blob("rgba").unwrap();
assert_eq!(0u8, blob[0]);
assert_eq!(0u8, blob[1]);
assert_eq!(0u8, blob[2]);
assert_eq!(0u8, blob[3]);
}