If you search something like that in google, you'll find a plugins (i hate to use them much) or some codes in 20-25 lines just for resizing. I don't think that it's a good idea to keep 20 lines of code in controller just for image resizing, and create service class for this more stupidness. after some minutes of searching i realize that Grails uses Groovy :) . I've found
Thumbnailator library, download the jar file - Thumbnailator-0.3.10.jar and copy it to the grails project Libraries directory.
def file=request.getFile("files[]")
//getting file from html form
def temp = new File(savePath)
//create file where i want to save original
temp.mkdirs()
//creates directories if they aren't exists
file.transferTo(temp)
//transfer file from form to the savePath
Thumbnails.of(temp).size(120,120).toFile(thumbPlace)
//resize our file to the 120x120 and save resized images to the thumbPlace
Oh and don't forget to add
import net.coobird.thumbnailator.*
Have a nice day...
--
короткий перевод :)
Чтобы изменить размеры фотки в Грейлс нужно (не то чтобы нужно но можно) скачать библиотеку, линк к которой я поставил выше, поместить ее в папку Libraries и указанный выше код поможет вам изменить размеры фотки закаченной с помощью формы.
Счастья...
Спасибо, клевая библиотека
ОтветитьУдалить