Skip to main content

SVG path data transformation toolkit

Project description

SVG path data transformation toolkit

A tool and a library for SVG path data transformations. Currently it supports a translation and a scaling.

Usage

As a Python library

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))
print(S.path_to_string(path, sfig=4))

As a command line tool

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] [-v]

SVG path data transformer

optional arguments:
  -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
  -v, --version  show program's version number and exit

Hint: a bash function to transform an SVG with a single path inside

function svg_transform() {
    selector='//_:path[1]/@d'
    input=$(</dev/stdin)
    old_path="$(xmlstarlet sel -t -v "$selector" <<< "$input")"
    [[ $? -ne 0 ]] && echo "could not parse SVG" && return 1
    new_path="$(svg_path_transform "$@" <<< "$old_path")"
    [[ $? -ne 0 ]] && echo "could not parse path" && return 1
    xmlstarlet ed -u "$selector" -v "$new_path" <<< "$input"
    [[ $? -ne 0 ]] && echo "could not update SVG" && return 1
    return 0
}

svg_transform --sx 2 --sy 2 < intput.svg > output.svg

Installation

pip install svg_path_transform

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

svg_path_transform-1.2.1.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

svg_path_transform-1.2.1-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file svg_path_transform-1.2.1.tar.gz.

File metadata

  • Download URL: svg_path_transform-1.2.1.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for svg_path_transform-1.2.1.tar.gz
Algorithm Hash digest
SHA256 7a9b193ea1f0af7f697d4124fa3efbcbbe1dc42901fd058b9137dd90a29e0b85
MD5 2a8d8b466ff0c7b83399bc025a5007c2
BLAKE2b-256 14427e116bf241a88added5a48cb61ff89b952d918ad28720d4967263313e79c

See more details on using hashes here.

File details

Details for the file svg_path_transform-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: svg_path_transform-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 10.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for svg_path_transform-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8fee5bc93bb710d5c6fd826d3c1b6093b1814227742d804b26d5c71abea13085
MD5 322454da951e796e5ead4c3d736bca7e
BLAKE2b-256 35907ed58d1a17889f1dede3e902d6907166bb5c79acd13348f4d082bd956c8f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page