Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

svg.transform

It’s a library to do svg.transforms.

It’s been on a list of things to do for years, and I haven’t implemented it, because I don’t need it, and making a library you don’t use is silly. But since nobody else is implementing this, even though it’s perfectly simple, well, I did it anyway. Anger-Driven Development is a thing. :-D

You are welcome.

I’m already looking for someone to take over this, and I haven’t even started writing code. You can take over svg.path too, I don’t use it anymore either.

Usage

You make transformation matrices with the following commands:

* svg.transform.translate_matrix(tx, ty=0): Returns a matrix that will translate in x and y

* svg.transform.scale_matrix(sx, sy=None): Returns a matrix that will scale in x and y

* svg.transform.rotate_matrix(r, cx=0, cy=0): Returns a matrix that will rotate, with optional offset

* svg.transform.skewx_matrix(ax): Returns a matrix that will skew in the x axis

* svg.transform.skewy_matrix(ay): Returns a matrix that will skew in the y axis

* svg.transform.matrix_matrix(a, b, c, d, e, f): Returns a free form translation matrix

For example like this:

>>> from svg import transform
>>>
>>> transform.translate_matrix(5, 8)
array([[ 1,  0,  5],
      [ 0,  1, 10],
      [ 0,  0,  1]])

You use this matrix by applying a matrix multiplication:

>>> from array import array
>>>
>>> old_x = 10
>>> old_y = 10
>>>
>>> res = transform.translate_matrix(5, 8) @ array("f", [old_x, old_y, 1])
>>> new_x = res[0]
>>> new_y = res[1]
>>> new_x, new_y
15.0, 18.0

You can also create transformation matrices directly from the SVG transform attributes:

>>> transform.parse("translate(-10 -20) scale(2) rotate(45) translate(5 10)")
array([[  1.05064398,  -1.70180705, -21.7648506 ],
       [  1.70180705,   1.05064398,  -0.98452498],
       [  0.        ,   0.        ,   1.        ]])

Contributors

Lennart Regebro <regebro@gmail.com>, Original Author

Changelog

0.1b1 (2023-05-01)

  • First release

Release files for svg.transform 0.1b1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for svg.transform 0.1b1
File Size Uploaded
svg.transform-0.1b1.tar.gz 4.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for svg.transform 0.1b1
File Interpreter ABI Platform
svg.transform-0.1b1-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 8.9 kB

Release files / svg.transform-0.1b1.tar.gz

Download URL svg.transform-0.1b1.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
5f3a6676d503d3e0abe4e6597ebf85b8e45035e33691d661f6762ec04b5a7cb2
BLAKE2b-256 checksum
How to use checksums
3292fe8ad0894813c8922d63fdfad9a7023944d6c4c2a9142d271a39975e82a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / svg.transform-0.1b1-py2.py3-none-any.whl

Download URL svg.transform-0.1b1-py2.py3-none-any.whl
Size 4.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
cfa31422fa63ceac374d6f32ec813525b9498ba5989a15144deab63abc1ccb3f
BLAKE2b-256 checksum
How to use checksums
08638b59aff29115f555bac006fbbf40055b17d81633c7f6ce8c46c32ef02cbc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release history Release notifications | RSS feed

This release

0.1b1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page