nlfiedler / magick-rust

Rust bindings for ImageMagick
https://crates.io/crates/magick_rust
Apache License 2.0
253 stars 68 forks source link

Question on using TransparentPaintImage #54

Open koeckc opened 4 years ago

koeckc commented 4 years ago

First of all thx for your great lib here.

I am basically trying to compare two images and afterwards use TransparentPaintImage to make the white parts in the diff transparent . Thats the part that is not working.. The code snippet here works perfect ... it only seems it has no effect on the image reference.

I somehow suppose the line with PixelGetPixel .. does not what i think. I tried alot but as a full noop i somehow cant exchange white with transparent pixel

On commandline or with go bindings it works ... just here i cant get it running

Do you have any idea what could be done ? Thx in advance c

See here my codesnippet:

    let mut left = MagickWand::new();
    let right = MagickWand::new();

    let left_binary: Binary = args[0].decode_as_binary()?;
    let right_binary: Binary = args[1].decode_as_binary()?;

    left.set_option("fuzz","10%").unwrap();
    left.set_option("highlight-color","red").unwrap();
    left.set_option("compose","Copy").unwrap();
    right.read_image_blob(right_binary.as_slice());
    left.read_image_blob(left_binary.as_slice());

    let (distortion, diff) =
        left.compare_images(&right, bindings::MetricType_FuzzErrorMetric);  
    let diff_image = diff.unwrap();

    diff_image.set_image_alpha_channel(bindings::AlphaChannelOption_OpaqueAlphaChannel).unwrap();
    let fuzz: f64 = 25.0;
    let mut filter2 = PixelWand::new();
    filter2.set_fuzz(fuzz);
    filter2.set_color("#FFFFFF").unwrap();
    filter2.set_alpha(1.0);
    let ei = unsafe { bindings::AcquireExceptionInfo() };
    let image = unsafe { bindings::GetImageFromMagickWand(diff_image.wand) };
    let mut pixel_info = unsafe { bindings::PixelGetPixel(filter2.wand)};

    let result = unsafe { bindings::TransparentPaintImage(image,&pixel_info,1.0,0,ei) };

    let resultwand = unsafe { bindings::NewMagickWandFromImage(image)};
nlfiedler commented 4 years ago

Sorry, I won't be of much help, this is far more complex than anything I ever tried to do with this library. It's possible that the filter flags are just slightly different/wrong with respect to the Go bindings, and that may explain why it does not work as intended. But that, too, is beyond my understanding of both this wrapper and ImageMagick in general.