prawnpdf / prawn

Fast, Nimble PDF Writer for Ruby
https://prawnpdf.org
Other
4.68k stars 688 forks source link

Image does not display correctly (GIF gmagick.depth or BitPerComponent) #1208

Closed ggenzone closed 3 years ago

ggenzone commented 3 years ago

I found a problem with a GIF image, I know that prawn doesn't support GIF image but ,I am not sure if the problem is prawn-gmagick or prawn.

Source Image:

example

Example code:

require "prawn/gmagick"

Prawn::Document.generate('example.pdf') do |pdf|
    pdf.image "example.gif"
end

Output: screenshot-github com-2021 06 03-13_23_41

In this specific case prawn-gmagick read the image and create this object

  def initialize image_blob    
    self.gimage = GMagick::Image.new image_blob
    self.bits = gimage.depth
    self.width = gimage.width
    self.height = gimage.height
  end
  def build_pdf_object(document)

    obj = document.ref!(      
        Type: :XObject,      
        Subtype: :Image,      
        ColorSpace: gimage.colorspace,      # = DeviceRGB
        Height: height,                     # = 243
        Width: width,                       # = 341
        BitsPerComponent: bits              # = 4
    )

    obj << gimage.unpack
...

The problem seems to be related to BitsPerComponent if I put 8 instead of the variable the image looks correct.

https://github.com/packetmonkey/prawn-gmagick/blob/master/lib/prawn/gmagick.rb#L27

Does anyone know if the problem is using image.depth as BitPerComponet or if the problem is internal in prawn?

Thanks!

gettalong commented 3 years ago

This is most certainly a bug in prawn-gmagick in that it doesn't correctly construct the needed PDF objects. I will close the issue here since you already have an issue in the prawn-gmagick repo.