fschutt / printpdf

An easy-to-use library for writing PDF in Rust
https://docs.rs/printpdf/
MIT License
777 stars 95 forks source link

png with transparency/alpha channel wouldn't shown #84

Open r4mp opened 3 years ago

r4mp commented 3 years ago

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));
fschutt commented 3 years ago

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

r4mp commented 3 years ago

wouldnt_shown

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

fschutt commented 3 years ago

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.

anhtumai commented 1 year ago

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

BXHlixiaodong commented 1 year ago

Hi, I find SoftMask is ready, but how to use it? it has no constructor function.

fschutt commented 1 year ago

@BXHlixiaodong This is a stub API, it doesn't work yet

mikeparisstuff commented 8 months ago

@fschutt, I'm also interested in soft mask functionality and would be willing to help out if you'd like. If interested, could you point out some relevant parts of the code where you think it would make sense to plug it in and I'll see if I can help out?

mikeparisstuff commented 8 months ago

I went ahead and submitted a PR that adds support for rgba8 images. I think it may be helpful to more people so ideally we can merge it, but I am as of now unblocked via my fork. Here is the diff https://github.com/fschutt/printpdf/pull/158