If I were to create an image as a Raphael.js object with the initial size [w1,h1], then scale it using the transform() method, how would I afterward retrieve its new size [w2,h2]? Because calling image.attr("width") returns w1, the initial width, not the width after the transformation.
I know you might say that I should simply multiply w1 and h1 with the scaling factors, but most of the times, a rotation transformation is also applied, which makes things a little more cumbersome.
So in short, is there a method in Raphael.js that retrieves the correct size of an object, regardless of any transformations that may have been applied to it?
There is a method for retrieving the bounding box of an element with and without transformation.
With transformation:
Without transformation:
You can extend Raphael.el with helper methods (if you are careful) that provide the width and height directly if this helps you. You could just use the bounding box method and return the portion that you’re interested in, but to be a bit more efficient I have calculated only the requested property using the matrix property on the elements and the position/width/height from attributes.
With usage:
Just include the script after you include Raphael. Note that it only works for elements with a width, height, x and y attributes, which is suitable for images. Raphael actually computes the bounding box from the path data, which transforms all of the points in the path and gets the min/max x/y values after transforming them.