The purpose of this plugin is to ease the manipulation of images in grails applications and also to ease the generation of thumbnails.
To install this game clone this project on your local filesystem:
git clone https://github.com/brunogamacatao/thumbnail
Grails versions 2.x does not allow the installation of local zipped plugins anymore, so you do have to perform the following commands inside the thumbnail plugin directory:
grails package-plugin
grails maven-install
After that, the plugins will be installed on your local maven repository and thus accessible to all your Grails applications.
- To use this plugin into you application you first have to open the
grails-app/conf/BuildConfig.groovy
file and uncomment themavenLocal()
line; - This plugin creates a new datatype
bgc.thumbnail.Thumbnail
you may use it whenever you want a picture on your domain classes; - The thumbnail plugin overrides the default scaffolding templates, so it will handle correctly the uploading and display of
bgc.thumbnail.Thumbnail
fields.
-
Create a project:
grails create-app thumbsample
-
Enter the created application directory:
cd thumbsample
-
Edit the
grails-app/conf/BuildConfig.groovy
and uncomment themavenLocal()
line (probably it is the 27 line); -
Install the Burning Image plugin:
grails install-plugin burning-image
-
Install the thumbnail plugin:
grails install-plugin thumbnail
-
Create a domain class:
grails create-domain-class Person
-
Edit the generated domain class
grails-app/domain/thumbsample/Person.groovy
:package thumbsample import bgc.thumbnail.Thumbnail class Person { String name Thumbnail picture static constraints = { name(blank: false) picture(blank: false) } }
-
Create a controller for the Person domain class:
grails create-controller Person
-
Edit the generated controller
grails-app/controller/thumbsample/PersonController.groovy
:package thumbsample class PersonController { def scaffold = true }
-
Run the project:
grails run-app
-
Enjoy it ! (open the
http://localhost:8080/thumbsample/person
URL on your browser)Open the generated views, create a new person, updated it and see the listing.
The thumbnail plugin includes a single tablib <g:thumbnail>
with the following attributes:
- id (mandatory): The id of the thumbnail attribute;
- width (optional): The width you want your thumbnail to be displayed;
- height (optional): The height you want your thumbnail to be displayed;
- class (optional): The css class to be applied on the generated html img tag.
<g:thumbnail id="${personInstance.picture.id}" width="50" height="50"/>