printpdf icon indicating copy to clipboard operation
printpdf copied to clipboard

png with transparency/alpha channel wouldn't shown

Open r4mp opened this issue 4 years ago • 8 comments

printpdf version: 0.3.3

If I try to add a png with transparency, the image wouldn't shown. Other png files works fine.

let mut image_file = File::open("test.png").unwrap();
let image = Image::try_from(image::png::PngDecoder::new(&mut image_file).unwrap()).unwrap();
image.add_to_layer(current_layer.clone(), Some(Mm(x)), Some(Mm(y)), None, Some(1.0), Some(1.0), Some(300.0));

r4mp avatar Dec 07 '20 00:12 r4mp

Can you upload the PNG file to GitHub?

As far as I know, images with an alpha channel aren't supported right now because that would require support for "soft masks" in the PDF, which isn't implemented yet.

Also see https://github.com/fschutt/printpdf/issues/61

fschutt avatar Dec 07 '20 05:12 fschutt

wouldnt_shown

It really seems to be the problem/reason you described.

r4mp avatar Dec 07 '20 20:12 r4mp

I'm putting soft masks on my todo list, it's not that hard to implement (you need to split out the alpha channel and then reference it as a separate greyscale image). Can't say when I'll get back to working on printpdf though.

fschutt avatar Dec 08 '20 01:12 fschutt

for newcomer going here, this is the workaround https://github.com/fschutt/printpdf/issues/119#issuecomment-1120434233 (work only with Rgba color space)

anhtumai avatar Nov 03 '22 21:11 anhtumai