Binding for set_image_background_color

This commit is contained in:
Magic Len
2018-08-12 23:05:45 +08:00
parent be0c6f5914
commit fd8f5e49a2
3 changed files with 48 additions and 1 deletions

View File

@ -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) /// Returns the image resolution as a pair (horizontal resolution, vertical resolution)
pub fn get_image_resolution(&self) -> Result<(f64, f64), &'static str> { pub fn get_image_resolution(&self) -> Result<(f64, f64), &'static str> {
let mut x_resolution = 0f64; let mut x_resolution = 0f64;

BIN
tests/data/rust.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

View File

@ -16,7 +16,7 @@
extern crate magick_rust; 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::error::Error;
use std::fs::File; use std::fs::File;
@ -263,3 +263,37 @@ fn test_color_reduction() {
assert_eq!(wand.get_image_width() * wand.get_image_height(), assert_eq!(wand.get_image_width() * wand.get_image_height(),
histogram.iter().fold(0, |total_colors, wand| total_colors + wand.get_color_count())); 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]);
}