dompdf / dompdf

HTML to PDF converter for PHP
https://dompdf.github.io/
GNU Lesser General Public License v2.1
10.47k stars 1.79k forks source link

Transparent images gif or png show previously used images #975

Open bbreukelen opened 9 years ago

bbreukelen commented 9 years ago

I am using domPDF from the page-merge branch. When I add a transparent png or gif image, the image itself is not transparent but a non-transparent image previously used in another page is vaguely show over the image as a watermark.

When I use ImageMagic (v3) the image is just white and when I disable ImageMagic the above described happened. Any workaround available for this?

Thanks!

bsweeney commented 9 years ago

Which branch (link, please)?

Do you have a sample image? As you can see from transparent image demo the latest release has fairly decent support for transparent images.

bbreukelen commented 9 years ago

Oh, apologies. I only just noticed that this is a branch in another fork. It's here: https://github.com/craigfrancis/dompdf/tree/page-merge

On the first page I used a few images that are not transparent. One of which looks like this: screen shot 2015-06-23 at 19 07 56

Then at the last page of the PDF, I use an 20x20 png red image which is 50% transparent. Instead of being redish it shows like this:

screen shot 2015-06-23 at 19 12 08

craigfrancis commented 9 years ago

Hi Bo, are you able to replicate it working when just using the dompdf library? i.e. without using my fork?

The only things my code does is try to combine the PDF's together:

https://github.com/dompdf/dompdf/compare/master...craigfrancis:page-merge

If you look at the "_combine_image_add" method, it really doesn't do anything to the contents of the images... so I suspect the problem is elsewhere.

That said, my fork was using quite an old version of DOMPDF... so I've just done a pull from master, so that might fix it?

bbreukelen commented 9 years ago

Hi Craig,

Thanks for your quick response. I cannot reproduce the issue on the master fork. I actually already pulled in the latest dompdf master but that didn't help.

It looks like maybe a variable is not unset after each page or something.

Thanks Bo On 25 Jun 2015 18:29, "Craig Francis" notifications@github.com wrote:

Hi Bo, are you able to replicate it working when just using the dompdf library? i.e. without using my fork?

The only things my code does is try to combine the PDF's together:

master...craigfrancis:page-merge https://github.com/dompdf/dompdf/compare/master...craigfrancis:page-merge

If you look at the "_combine_image_add" method, it really doesn't do anything to the contents of the images... so I suspect the problem is elsewhere.

That said, my fork was using quite an old version of DOMPDF... so I've just done a pull from master, so that might fix it?

— Reply to this email directly or view it on GitHub https://github.com/dompdf/dompdf/issues/975#issuecomment-115310697.

craigfrancis commented 9 years ago

Sorry to hear that, unfortunately I don't really have the time to look though how all of this works at the moment... the fork I created was only a partial implementation so I could just stitch some basic files together... not sure if you have any experience in coding in PHP, but maybe you could ask around to find out how alpha transparency is handled in PDF's... it might just need some extra bits being copied over?

bbreukelen commented 9 years ago

I did some debugging and found out that as soon as I use the dompdf_pages class transparent PNGs will not show up correctly, even if the PDF only has a single page. The XObjects between the normal dompdf object and the page combined dompdf object are exactly the same so it looks to me like something might have been changed in other parts of the PDF to handle transparency.

Does anyone have an idea what to look for? Thanks

bbreukelen commented 9 years ago

Workaround for whomever runs into this issue. I don't know how to solve it, but if you don't care about transparent PNGs and don't want the issue of the previous image showing as a mask through the next one, do the following:

In lib/class.pdf.php on below line 4628 (immediately underneath function addImagePng($file, $x, $y, $w = 0.0, $h = 0.0, &$img, $is_mask = false, $mask = null) {...}

Add this line: $is_mask = false; $mask = null;