-
Notifications
You must be signed in to change notification settings - Fork 688
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
Palleted PNG w. transparency unsupported #783
Comments
@mfly: Thanks for the detailed bug report! We have a policy of no external runtime dependencies, so using a third-party gem dependency is not an option for us. It seems like for now we should think about raising a |
@mfly: I forgot to mention that while Prawn itself cannot use external dependencies, that our entire image system is replaceable. You might give https://github.com/packetmonkey/prawn-gmagick a try and see if it fixes your problem. |
@sandal Thanks for instant reaction :) |
@mfly What does the |
@edborden: The |
I know it's been a while since this was last discussed, but what is the currently recommended work-around for this? Does |
While I understand the "no external runtime dependency" stance, it makes little sense IMHO to provide a broken image handling implementation instead. Architecturally it would be more sound to either remove the default PNG image handling or to at least raise a warning when using it. |
@Fryie: I agree, and already mentioned this in the current thread.
|
@packetmonkey I marked this as a bug... because as @Fryie said... broken behavior without a warning is pretty much a defect. Consider fixing in a future release. 😄 |
Just to chime in, I can confirm that adding the |
Maybe a section in the README explaining that the image engine can be replaced would be helpful too. :) |
I ran this test script with prawn 2.0.2 and we are now throwing an exception for transparent palleted PNG files added in 8ebe282 ~/Code/prawn-png $ ruby prawn_test.rb
/Users/evan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/prawn-2.0.2/lib/prawn/images/png.rb:71:in `block in initialize': Pallete-based transparency in PNG is not currently supported. (Prawn::Errors::UnsupportedImageType)
See https://github.com/prawnpdf/prawn/issues/783
from /Users/evan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/prawn-2.0.2/lib/prawn/images/png.rb:45:in `loop'
from /Users/evan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/prawn-2.0.2/lib/prawn/images/png.rb:45:in `initialize'
from /Users/evan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/prawn-2.0.2/lib/prawn/images.rb:87:in `new'
from /Users/evan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/prawn-2.0.2/lib/prawn/images.rb:87:in `build_image_object'
from /Users/evan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/prawn-2.0.2/lib/prawn/images.rb:66:in `image'
from prawn_test.rb:4:in `block (2 levels) in <main>'
from /Users/evan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/prawn-2.0.2/lib/prawn/document.rb:225:in `instance_eval'
from /Users/evan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/prawn-2.0.2/lib/prawn/document.rb:225:in `initialize'
from /Users/evan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/prawn-2.0.2/lib/prawn/document.rb:141:in `new'
from /Users/evan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/prawn-2.0.2/lib/prawn/document.rb:141:in `generate'
from prawn_test.rb:3:in `block in <main>'
from prawn_test.rb:2:in `each'
from prawn_test.rb:2:in `<main>'
~/Code/prawn-png $ So we won't kick out known bad PDFs and I'm still open to a PR that will implement native palleted PNG transparency support. Closing the issue. |
Looks like there is a fix for this. Can we get it merged in? |
@mfly @edborden @Siyfion @danielgrippi @sublimecoder @kriztynna Sorry for addressing so many people but I'm curious what is your use case? I didn't even think that palette transparency in PNG is used so widely. I though it's just one of those rare edge cases that one or two users stumble upon but apparently many people use those palette PNGs all the time. So could you please share your use case and why you use palette transparency instead of, say, 8-bit alpha channel? |
Our system uses prawn for PNG to PDF conversion. Images are provided by
|
We use it in a similar fashion to @mfly. We create PDFs that contain user input and the pngs are not always under our control. The interesting thing is prawn 1.3.0 seems to be able to handle most of these pngs with out issue so we're just using 1.3 until the next release. |
@sublimecoder This is interesting. We used to have incomplete support for palette transparency. It only keeps color data but completely loses transparency. It won't complain but the output would be incorrect. |
@cheba hmm interesting so did it just flatten it or did it manipulate the image in another manner to strip the transparency? |
@sublimecoder Quick code inspection seem to show that only color would be kept and transparency data would simply be ignored. In pseudo code it would look like the following transformation: def pixel_color(r, g, b, a)
[r, g, b, 1.0]
end |
Similar use case here, working with 3rd party PNGs that happen to use On Sat, Dec 19, 2015 at 4:12 AM Alexander Mankuta notifications@github.com
|
I was creating some PDF files with PNG images and some of them came out with transparency issues. After some tests I narrowed the issue to palleted PNG files. Unfortunately, most of images I use are palleted so it was a real problem.
Quick look at the code reveals that transparency is completely broken for palleted files:
https://github.com/prawnpdf/prawn/blob/master/lib/prawn/images/png.rb#L211
Then I created a test script and a set of test images (https://dl.dropboxusercontent.com/u/20390548/prawn-png.tar.bz2). As expected, everything seems to work, except the palleted PNG with transparency.
Maybe it would be a better idea to use some external library than to try implement PNG handling inside prawn?
Suggested workaround for issues with transparency in PNG files is to use an external tool to convert files into rgba/grayscale mode before using them with prawn.
For me, the best solution is flattening the files with white background and converting it to 8-bit-per-channel RGB with the following command:
The text was updated successfully, but these errors were encountered: