Skip to content

Instantly share code, notes, and snippets.

@masanobuimai
Created February 13, 2009 04:12
Show Gist options
  • Save masanobuimai/63044 to your computer and use it in GitHub Desktop.
Save masanobuimai/63044 to your computer and use it in GitHub Desktop.
Grails:画像をアップロードして,サムネイル作成。
grails install-plugin http://www.arquetipos.co.cr/blog/files/grails-image-tools-1.0.3.zip
class Picture {
byte[] imagefile
}
def save = {
def downloadedFile = request.getFile('imagefile')
def pictureInstance = new Picture(params)
def imageTool = new ImageTool()
if (downloadedFile && pictureInstance.save()) {
String imagepath = "${grailsAttributes.applicationContext.getResource('images/').file}${File.separatorChar}${pictureInstance.id}.jpg"
downloadedFile.transferTo(new File(imagepath))
imageTool.load(imagepath)
imageTool.thumbnail(140)
imageTool.writeResult(imagepath, "JPEG")
imageTool.square()
flash.message = "Picture ${pictureInstance.id} created(${imagepath})"
redirect(action: show, id: pictureInstance.id)
}
else {
render(view: 'create', model: [pictureInstance: pictureInstance])
}
}
<td><img src="${createLinkTo(dir:'images', file:pictureInstance.id+'.jpg')}"/></td>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment