There is a method for retrieving the bounding box of an element with and without transformation.
With transformation:
var bbox = image.getBBox(),
width = bbox.width,
height = bbox.height;
Without transformation:
var bbox = image.getBBoxWOTransform(),
width = bbox.width,
height = bbox.height;
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.
(function (r) {
function getX() {
var posX = this.attr("x") || 0,
posY = this.attr("y") || 0;
return this.matrix.x(posX, posY);
}
function getY() {
var posX = this.attr("x") || 0,
posY = this.attr("y") || 0;
return this.matrix.y(posX, posY);
}
function getWidth() {
var posX = this.attr("x") || 0,
posY = this.attr("y") || 0,
maxX = posX + (this.attr("width") || 0),
maxY = posY + (this.attr("height") || 0),
m = this.matrix,
x = [
m.x(posX, posY),
m.x(maxX, posY),
m.x(maxX, maxY),
m.x(posX, maxY)
];
return Math.max.apply(Math, x) - Math.min.apply(Math, x);
}
function getHeight() {
var posX = this.attr("x") || 0,
posY = this.attr("y") || 0,
maxX = posX + (this.attr("width") || 0),
maxY = posY + (this.attr("height") || 0),
m = this.matrix,
y = [
m.y(posX, posY),
m.y(maxX, posY),
m.y(maxX, maxY),
m.y(posX, maxY)
];
return Math.max.apply(Math, y) - Math.min.apply(Math, y);
}
r.getX = getX;
r.getY = getY;
r.getWidth = getWidth;
r.getHeight = getHeight;
}(Raphael.el))
With usage:
var x = image.getX();
var y = image.getY();
var width = image.getWidth();
var height = image.getHeight();
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.