Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question on using TransparentPaintImage #54

Open
koeckc opened this issue Oct 13, 2019 · 1 comment
Open

Question on using TransparentPaintImage #54

koeckc opened this issue Oct 13, 2019 · 1 comment

Comments

@koeckc
Copy link

koeckc commented Oct 13, 2019

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
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants