asciidoctor / docker-asciidoctor

:ship: A Docker image for using the Asciidoctor toolchain to process AsciiDoc content
https://hub.docker.com/r/asciidoctor/docker-asciidoctor/
Other
324 stars 149 forks source link

Add prawn-gmagick gem #121

Open mojavelinux opened 4 years ago

mojavelinux commented 4 years ago

The prawn-gmagick gem is a drop-in replacement for the image processing in Asciidoctor PDF that uses GraphicsMagick under the covers. It has the benefit of making PDF conversion of documents containing images substantially faster. Image decoding in pure Ruby is quite slow, so this gem delegates the work to GraphicsMagick to speed it up. It also adds support for more image formats, like GIF. The downside is that it also requires the GraphicsMagick package to be installed. If it doesn't add too much to the size of the image (at least the box image), I think it is well worth adding.

See https://github.com/asciidoctor/asciidoctor-pdf#supporting-additional-image-file-formats

bcouetil commented 4 years ago

Looking forward to this, PDF conversion can be sometimes significantly slow :smile:

mojavelinux commented 4 years ago

While writing tests, I've noticed that prawn-gmagick can mess up the palette of some PNGs. I'm not sure how prevalent this problem is, but we may need to provide an escape hatch (in Asciidoctor PDF) so it doesn't get automatically loaded if it is a real problem.

das-g commented 4 years ago

In a container of this image, prawn-gmagick can be installed as follows:

apk add graphicsmagick-dev ruby-dev musl-dev gcc
gem install prawn-gmagick

As documented at https://github.com/asciidoctor/asciidoctor-pdf#supporting-additional-image-file-formats, asciidoctor-pdf will then automatically use that gem for embedding images.

fhaefemeier commented 4 years ago

Tried to embed image in PDF. Source is a URL (e.g. https://img.shields.io/badge/Status-Open-red). But get the warning "asciidoctor: WARNING: could not embed image: /tmp/image-20200813-1-1h5my3o; image file is an unrecognised format; install prawn-gmagick gem to add support" after enable the attribute allow-uri-read. Are there any plans to have this GEM installed in the provided image?

fhaefemeier commented 4 years ago

Tried to embed image in PDF. Source is a URL (e.g. https://img.shields.io/badge/Status-Open-red). But get the warning "asciidoctor: WARNING: could not embed image: /tmp/image-20200813-1-1h5my3o; image file is an unrecognised format; install prawn-gmagick gem to add support" after enable the attribute allow-uri-read. Are there any plans to have this GEM installed in the provided image?

I see, after testing to load the missing packages it isn't an issue with the package. I get the same error.

mojavelinux commented 4 years ago

The warning message is unrelated to the problem in this case. You have specified a path to an SVG, but not indicated that it's an SVG. You can do so by appending .svg to the URL or adding the format=svg attribute to the macro.

mojavelinux commented 2 years ago

While writing tests, I've noticed that prawn-gmagick can mess up the palette of some PNGs. I'm not sure how prevalent this problem is, but we may need to provide an escape hatch (in Asciidoctor PDF) so it doesn't get automatically loaded if it is a real problem.

Asciidoctor PDF 2 will provide a script you can use to prevent prawn-gmagic from handling PNG images in this situation.

asciidoctor-pdf -r asciidoctor/pdf/nogmagick doc.adoc

It still leaves prawn-gmagick enabled for other image formats since they wouldn't otherwise be supported.