views:

326

answers:

1

I'm using grails j2d which in turns uses GraphicsBuilder to make a simple service to scale an image. My problem is specifically accessing the downloaded image height and width attributes in order to pass the correct parameters to the scale method. How do I access these attributes inside the transformations 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  A: 

I don't know the J2D plugin at all, but you might check into what the delegate is for the closure you're passing to the image call. Add a line like "def d = delegate" before the transformations call, and debug this to see what type the delegate is. If it's an Image, then you ought to be able to get delegate.width or delegate.w or some such.

Bill James