Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8731277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:11:59+00:00 2026-06-13T09:11:59+00:00

If I were to create an image as a Raphael.js object with the initial

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:12:00+00:00Added an answer on June 13, 2026 at 9:12 am

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an image animation using Raphael JS. I want the effect
I want to try to create an image using NSdata. If imageWithData: method of
I am using Raphael.js to create polygons, (or actually closed paths) over an image.
I'm using Raphael js framework to create interactive svg image on client: var paper
I'm trying to create an image using matplotlib.pyplot.imshow() . However, when I run the
I'm trying to create an image by using binary data that I received from
I am using AQGridView to create an image gallery that has about 21 items.
I am running following code to create bmp image from pdf using Ghost4j i
I need to create and save image thumbnails in database. I am using django
I create an image in C# which should contain some text in Japanese. Then

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.