Created
February 13, 2009 04:12
-
-
Save masanobuimai/63044 to your computer and use it in GitHub Desktop.
Grails:画像をアップロードして,サムネイル作成。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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