import javax.imageio.ImageIO import java.io.FileOutputStream import org.springframework.beans.factory.InitializingBean class ThumbnailController implements InitializingBean { def grailsApplication def thumbnailService def show = { def rasterEntry = RasterEntry.get(params.id) if ( !rasterEntry ) { flash.message = "RasterEntry not found with id ${params.id}" redirect(action: list) } else { def projectionType = params.projectionType; RasterDataSet rasterDataSet = rasterEntry.rasterDataSet RasterFile rasterFile = RasterFile.findWhere(rasterDataSet: rasterDataSet, type: "main") def size = params.size?.toInteger() def mimeType = "image/jpeg" if ( !size ) size = grailsApplication.config.thumbnail.defaultSize String cacheDirPath = grailsApplication.config.thumbnail.cacheDir String thumbnailPrefix = "${rasterEntry.id}-${size}-${projectionType}" File outputFile = thumbnailService.getThumbnail( cacheDirPath, thumbnailPrefix, size, mimeType, rasterFile.name, rasterEntry.entryId, projectionType ) if ( outputFile.exists() && (outputFile.length() > 0) ) { def image = ImageIO.read(outputFile) response.contentType = mimeType ImageIO.write(image, "jpeg", response.outputStream) } } } def frame = { def videoDataSet = VideoDataSet.get(params.id) if ( !videoDataSet ) { flash.message = "VideoDataSet not found with id ${params.id}" redirect(action: list) } else { response.contentType = "image/png" VideoFile videoFile = VideoFile.findWhere(videoDataSet: videoDataSet, type: "main") def size = params.size?.toInteger() if ( !size ) grailsApplication.config.thumbnail.defaultSize String cacheDirPath = grailsApplication.config.thumbnail.cacheDir String thumbnailPrefix = "${videoDataSet.id}-${size}" File outputFile = thumbnailService.getFrame(cacheDirPath, thumbnailPrefix, size, videoFile.name) def image = ImageIO.read(outputFile) response.contentType = "image/png" ImageIO.write(image, "png", response.outputStream) } } def asHTML = { def size = params.size if ( !size ) grailsApplication.config.thumbnail.defaultSize render(contentType: "text/html") { html { body { img(src: createLink(action: "show", id: params.id, params: params), width: size, height: size) } } } } def proxy = { def url = "${params.url}" params.each { url += "&${it}" } println url def text = url.toURL().text println text render(contentType: "text/xml", text: text) } public void afterPropertiesSet() { //To change body of implemented methods use File | Settings | File Templates. } }