News
- 12 February 2010: upgraded to GfxBuilder 0.2.3 and Grails 1.2.0
- 15 October 2009: upgraded to GfxBuilder 0.2.1
- 9 July 2008: added SVG support, image caching
- 4 June 2008: first release!
Description
J2D plugin allows you to draw images on the fly with Java2D, using
GfxBuilder under the covers . The first release supports regular image output (gif|png|svg). Please visit
GfxBuilder's site to learn more about the nodes that can be used, several graphic examples are also available at
http://jroller.com/aalmiray/tags/graphicsbuilder and
http://jroller.com/aalmiray/tags/gfxThe current version of the
j2d plugin is
0.4, which was released on
February 12th 2010.
Usage
The plugin works by adding a new method to all controller classes:
renderImage. This method takes a Map and a Closure as parameters, the Map will specify optional properties and hints for image processing (like width, height and format), the Closure being the actual graphics instructions to be rendered. Here is a basic example that outputs two colored squares (one red, one blue) in png format (the default value)
class MyController {
def graph = {
renderImage(width: 100, height: 100) {
rect(x: 0, y: 0, width: 100, height: 100, fill: 'red')
// same graphic node but using property aliases
rect(x: 20, y: 20, w: 60, h: 60, f: color('#00F'))
}
}
}Parameters
The following is a list of currently supported parameters in
renderImage| Name | Type | Description |
|---|
| width | int | the width of the image (default=1) |
| height | int | the height of the image (default=1) |
| type | String | the output format [png,gif,svg] (default=png) |
| name | String | the name of the file where the image will be saved |
| ttl | int | time-to-live how long will the cached image will be stored (in milliseconds) |