https://github.com/igrmk/svg_path_transform
SVG path data transformation toolkit
https://github.com/igrmk/svg_path_transform
cli python svg svg-path
Last synced: 8 months ago
JSON representation
SVG path data transformation toolkit
- Host: GitHub
- URL: https://github.com/igrmk/svg_path_transform
- Owner: igrmk
- License: mit
- Created: 2021-09-06T09:19:29.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2021-10-18T00:57:49.000Z (over 4 years ago)
- Last Synced: 2024-09-16T11:28:24.387Z (almost 2 years ago)
- Topics: cli, python, svg, svg-path
- Language: Python
- Homepage:
- Size: 24.4 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
SVG path data transformation toolkit
====================================
[](https://pypi.org/project/svg-path-transform/)
A tool and a library for SVG path data transformations.
Currently it supports a translation and a scaling.
Usage
-----
As a Python library
```python
import svg_path_transform as S
path = S.parse_path("m 2 2 l 2 2")
path = S.translate_and_scale(path, s=(1, 3))
path = S.translate_and_scale(path, t=(3, 4))
path = S.morph(path, lambda p: [p[0] * 2, p[1] * 2])
print(S.path_to_string(path, sfig=4))
```
As a command line tool
```bash
svg_path_transform --dx 100 --dy 100 <<< "m 2 2 l 2 2"
```
Command line parameters
```
usage: svg_path_transform [-h] [--dx N] [--dy N] [--sx N] [--sy N] [--sfig N] [--ndig N] [--seg N] [--pretty-print] [-v]
SVG path data transformer
options:
-h, --help show this help message and exit
--dx N translate x by N
--dy N translate y by N
--sx N scale x by N
--sy N scale y by N
--sfig N round to N significant figures
--ndig N round to N decimal places
--seg N convert to straight line segments with a given max distance
--pretty-print pretty print the input path and exit
-v, --version show program's version number and exit
```
Hint: a bash function to transform an SVG with a single path inside
```bash
function svg_transform() {
selector='//_:path[1]/@d'
input=$( output.svg
```
Installation
------------
```bash
pip install svg_path_transform
```