(Quick Reference)

7 Inline Images - Reference Documentation

Authors: Grails Plugin Collective

Version: 1.0.0

7 Inline Images

This plugin adds support for inline images via data uris This is useful for situations where the images you need to imbed in a rendered PDF or image are generated by the application itself.

For example, your application may generate barcodes that you don't necessarily want to expose but want to include in your generated PDFs or images. Using inline images, you can include the image bytes in the document to be rendered.

To make this easier, the plugin provides tags to render byte arrays as common image formats (i.e. gif, png and jpeg).

The tags are under the namespace rendering and are called inlinePng, inlineGif and inlineJpeg. They all take a single argument, bytes, which is a byte containing the raw bytes of the images. This will result in an img tag with a src attribute of a suitable data uri. Any other parameters passed to the tag will be expressed as attributes of the resultant img tag.

Here is an example of how this could be used to include a local (i.e. from the filesystem) image in a generated pdf/image.

class SomeController {

def generate = { def file = new File("path/to/image.png") renderPng(template: "thing", model: [imageBytes: file.bytes]) }

}

In the view…

<html>
    <head></head>
    <body>
        <p>Below is an inline image</p>
        <rendering:inlinePng bytes="${imageBytes}" class="some-class" />
    </body>
</html>