Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

131
Views
My fabric.js sclaing methods don't work after object rotation

I have a scaling method for my Fabric.js objects, so they don't scale outside of the borders. But when I rotate the objects, the scaling method does not work correctly. My guess is that the scaling method does not take in account that the old top is now the right side of the object. Does someone know how to make it take the rotation in account when scaling?

let scalingProperties = {
    'left': 0,
    'top': 0,
    'scaleX': 0,
    'scaleY': 0
}

export function scaling(e) {
    const shape = e.target;
    const maxWidth = shape.canvas.width;
    const maxHeight = shape.canvas.height;

    //left border
    if(shape.left < 0) {
        shape.left = scalingProperties.left = 0;
        shape.scaleX = scalingProperties.scaleX;
    } else {
        scalingProperties.left = shape.left;
        scalingProperties.scaleX = shape.scaleX;
    }

    //right border
    if((shape.scaleX * shape.width) + shape.left > maxWidth) {
        shape.scaleX = (maxWidth - scalingProperties.left) / shape.width;
    } else {
        scalingProperties.scaleX = shape.scaleX;
    }

    //top border
    if(shape.top < 0) {
        shape.top = scalingProperties.top = 0;
        shape.scaleY = scalingProperties.scaleY;
    } else {
        scalingProperties.top = shape.top;
        scalingProperties.scaleY = shape.scaleY;
    }

    //bottom border
    if((shape.scaleY * shape.height) + shape.top > maxHeight) {
        shape.scaleY = (maxHeight - scalingProperties.top) / shape.height;
    } else {
        scalingProperties.scaleY = shape.scaleY;
    }
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Let's visualize your problem:

enter image description here

A simple approach for this would be to enlarge the container you use, so its bounds would not be overflown even if the content rotates. The worst-case-senario is when the rotation's amount is (n + 1) * pi / 4, where n is a natural number.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!