How to get SVG transform Matrix values ​​from rotation / scaling

Essentially, I'm looking for a PHP function or equation that will output the Matrix values ​​used in the SVG transform.

I hunted high and low and, unfortunately, did not find anything.

I know the rotate () and scale () functions well, but this is not what I need.

I need to be able to take the rotation angle in degrees along with x / y scale data and output a series of values ​​in the SVG transformation format matrix (a, b, c, d, e, f)

Ideally, I would like to do this in PHP, but as said, a standard mathematical equation will also help.

Hope someone can point me in the right direction.

+3
source share
2 answers

, . SVG, :

rot(a)       := matrix(cos(a), sin(a), -sin(a), cos(a), 0, 0)
scale(sx,sy) := matrix(sx, 0, 0, sy, 0, 0)

( ), :

rot(a)*scale(sx,sy) = matrix(sx*cos(a), sx*sin(a), -sy*sin(a), sy*cos(a), 0, 0)
scale(sx,sy)*rot(a) = matrix(sx*cos(a), sy*sin(a), -sx*sin(a), sy*cos(a), 0, 0)
+3
function selectElement(evt) {
        selectedElement = evt.target;
        currentX = evt.clientX;
        currentY = evt.clientY;
        currentMatrix = selectedElement.getAttributeNS(null, "transform").slice(7, -1).split(' ');
        alert(currentMatrix );
    }`<svg><rect class="draggable" x="30" y="30" width="80" height="80" fill="blue" transform="matrix(1 0 0 1 0 0)"
        onmousedown="selectElement(evt)"</svg> />`
0

All Articles