How to use Grails j2d plugin to scale an image

I am using grails j2d which I use in turn GraphicsBuilder

to make a simple image scaling service. My problem is special access to the uploaded image's height and width attributes to pass the correct parameters to the scaling method. How do I access these attributes inside the transformation closure?

Controller {
   def scale = {
       def targetW = new Integer(params?.w?:64)
       def targetH = new Integer(params?.h?:48)
       renderImage( [width: targetW  ,height: targetH ] ) {
          image( url: params?.url ) {
             transformations {
                scale( x: 1 , y: 1 , interpolation: 'bicubic' )
             }
          }
       }
    }
}

      

+1


source to share


2 answers


I don't know the J2D plugin at all, but you can check what the delegate is, for the closure you pass to the image call. Add a line like "def d = delegate" before calling the transform and debug that to see what type is the delegate. If this is an image, then you should be able to get delegate.width or delegate.w or some of them.



+1


source


The neswest j2d plugin provides these values, so you can execute the parameters as usual.



0


source







All Articles