Question

I have ImageController with resize method:

def resize = {
    def pht = Photos.findByTypeAndPhotourl(params.type, params.photourl)
    if (pht != null) {
      BufferedImage source = ImageIO.read(new File(pht.photo))
      ImageResizer imageResizer = new ImageResizer()
      BufferedImage result = imageResizer.resize(source, Integer.parseInt(params.width), Integer.parseInt(params.height))
      imageResizer.writePNG(result, params.name)

      render "OK"
    } else {
      render "Error"
    }
  }

As you can see - it writes BufferedImage instance (resized image) on the disk. But i want to return image in response so resized image will be displayed in browser when user requests resize method(or he will be able to download it). It's smth like file serving problem...

Does it right way to use:

ImageIO.write(result, "png", response.getOutputStream())
Was it helpful?

Solution

Yeah, ImageIO is the way to go

See

Image resize in Grails

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top