packetmonkey / prawn-gmagick

Use GraphcisMagick to load images into a Prawn document
https://github.com/packetmonkey/prawn-gmagick/
13 stars 6 forks source link

Using prawn-gmagick on PNGs with an alpha channel results in a bloated file #14

Closed tkfu closed 5 years ago

tkfu commented 7 years ago

To minimally reproduce: Using the attached test.png, run the following ruby script:

require 'prawn'

pdf = Prawn::Document.new
pdf.text "Minimal test case"
pdf.image "test.png",:width => 500
pdf.render_file "test-prawn.pdf"

require 'prawn/gmagick'

pdf2 = Prawn::Document.new
pdf2.text "Minimal test case"
pdf2.image "test.png",:width => 500
pdf2.render_file "test-prawn-gmagick.pdf"

Then, look at the file sizes:

$ ls -lh *.pdf
-rw-rw-r-- 1 jon jon 884K Jul  4 23:16 test-prawn-gmagick.pdf
-rw-rw-r-- 1 jon jon  14K Jul  4 23:16 test-prawn.pdf

And check out the image object breakdown using the poppler suite:

$ pdfimages -list test-prawn.pdf
page   num  type   width height color comp bpc  enc interp  object ID x-ppi y-ppi size ratio
--------------------------------------------------------------------------------------------
   1     0 image    1804   499  rgb     3   8  image  no         7  0   260   260 3320B 0.1%
   1     1 smask    1804   499  gray    1   8  image  no         7  0   260   260 8869B 1.0%
$ pdfimages -list test-prawn-gmagick.pdf
page   num  type   width height color comp bpc  enc interp  object ID x-ppi y-ppi size ratio
--------------------------------------------------------------------------------------------
   1     0 image    1804   499  rgb     3   8  image  no         7  0   260   260 3528B 0.1%
   1     1 smask    1804   499  gray    1   8  image  no         7  0   260   260  879K 100%

Now, in this trivial case with a single tiny PNG using simple transparency, I added almost 900k to the pdf. When this first came up for real, I went from a 3MB pdf to an 80MB pdf.

mojavelinux commented 7 years ago

@packetmonkey This fix is vitally important for Asciidoctor PDF, which relies on prawn-gmagick to substantially decrease the time it takes to generate a PDF. Jon has submitted a PR. If there's anything I can do to help get this into a release, please don't hesitate to ask. Thanks in advance!

mojavelinux commented 7 years ago

@pointlessone would it be possible to get the associated PR merged?

pointlessone commented 7 years ago

@mojavelinux Which one is that?

mojavelinux commented 7 years ago

This one: https://github.com/packetmonkey/prawn-gmagick/pull/15

pointlessone commented 7 years ago

@mojavelinux I don't have access. I'm not involved with this project. I'm afraid it'll have to wait until Evan has some time.

mojavelinux commented 7 years ago

Thanks for the info!