diff --git a/src/wand/magick.rs b/src/wand/magick.rs index 9b3767c..0653b65 100644 --- a/src/wand/magick.rs +++ b/src/wand/magick.rs @@ -381,6 +381,19 @@ impl MagickWand { } } + /// 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) } { + + bindings::MagickBooleanType::MagickTrue => Ok(()), + + _ => Err("SetImageBackgroundColor returned false") + + } + + } + /// Returns the image resolution as a pair (horizontal resolution, vertical resolution) pub fn get_image_resolution(&self) -> Result<(f64, f64), &'static str> { let mut x_resolution = 0f64; diff --git a/tests/data/rust.png b/tests/data/rust.png new file mode 100644 index 0000000..11c6de6 Binary files /dev/null and b/tests/data/rust.png differ diff --git a/tests/lib.rs b/tests/lib.rs index 7eccc5d..ef6d271 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -16,7 +16,7 @@ extern crate magick_rust; -use magick_rust::{MagickWand, magick_wand_genesis, MetricType, ColorspaceType, FilterType, DitherMethod}; +use magick_rust::{MagickWand, magick_wand_genesis, MetricType, ColorspaceType, FilterType, DitherMethod, PixelWand, bindings}; use std::error::Error; use std::fs::File; @@ -263,3 +263,37 @@ fn test_color_reduction() { assert_eq!(wand.get_image_width() * wand.get_image_height(), histogram.iter().fold(0, |total_colors, wand| total_colors + wand.get_color_count())); } + +#[test] +fn test_set_image_background_color() { + START.call_once(|| { + + magick_wand_genesis(); + + }); + + let wand = MagickWand::new(); + + assert!(wand.read_image("tests/data/rust.png").is_ok()); + + + let mut pw = PixelWand::new(); + + pw.set_color("#0000FF").unwrap(); + + + wand.set_image_background_color(&pw).unwrap(); + + + wand.set_image_alpha_channel(bindings::AlphaChannelOption::RemoveAlphaChannel).unwrap(); + + + let blob = wand.write_image_blob("rgb").unwrap(); + + + assert_eq!(0u8, blob[0]); + + assert_eq!(0u8, blob[1]); + + assert_eq!(255u8, blob[2]); +} \ No newline at end of file