Skip to main content

A ctypes API for thorvg, a vector graphics engine supporting SVG and Lottie formats.

Project description

thorvg-python

A ctypes API for thorvg, with additional functions for getting Pillow Image.

The functions mostly follow thorvg/src/bindings/capi/thorvg_capi.h

Documentations: https://thorvg-python.readthedocs.io/en/latest/

Table of contents

Installing

Note that thorvg is included in the wheel package, you need not install libthorvg. Version bundled is the version available on Conan (Currently 1.0.1)

To install, run the following:

pip3 install thorvg-python

Pillow is optional dependency. It is required for SwCanvas.get_pillow(). To also install Pillow, run:

pip3 install thorvg-python[full]

Examples

Drawing and getting pillow image

import thorvg_python as tvg

engine = tvg.Engine(threads=4)
canvas = tvg.SwCanvas(engine)
canvas.set_target(512, 256)  # w, h

rect = tvg.Shape(engine)
rect.append_rect(10, 10, 64, 64, 10, 10)  # x, y, w, h, rx, ry
rect.set_fill_color(32, 64, 128, 100)  # r, g, b, a
canvas.push(rect)

canvas.update()
canvas.draw(True)
canvas.sync()

im = canvas.get_pillow()
canvas.destroy()
engine.term()

Rendering lottie animation

import thorvg_python as tvg
from PIL import Image

engine = tvg.Engine(threads=4)
canvas = tvg.SwCanvas(engine)
canvas.set_target(512, 512)  # w, h

animation = tvg.LottieAnimation(engine)
picture = animation.get_picture()
picture.load("tests/test.json")
picture.set_size(512, 512)

canvas.push(picture)

ims: list[Image.Image] = []
result, total_frame = animation.get_total_frame()
result, duration = animation.get_duration()
frame_duration = duration / total_frame
# fps = total_frame / duration
for i in range(int(total_frame)):
    animation.set_frame(i)
    canvas.update()
    canvas.draw(True)
    canvas.sync()
    im = canvas.get_pillow()
    ims.append(im)

ims[0].save("test.apng", save_all=True, append_images=ims[1:], duration=frame_duration * 1000)

Building from source

To build wheel, run the following:

git clone --recursive https://github.com/laggykiller/thorvg-python.git
cd thorvg-python

# To build wheel
python3 -m build .

# To install directly
pip3 install .

Development

To run tests:

pip install pytest
pytest

To lint:

pip install ruff mypy isort
mypy
isort .
ruff check
ruff format

Credits

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

thorvg_python-1.1.1.tar.gz (76.2 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

thorvg_python-1.1.1-py3-none-win_arm64.whl (845.3 kB view details)

Uploaded Python 3Windows ARM64

thorvg_python-1.1.1-py3-none-win_amd64.whl (957.4 kB view details)

Uploaded Python 3Windows x86-64

thorvg_python-1.1.1-py3-none-win32.whl (844.9 kB view details)

Uploaded Python 3Windows x86

thorvg_python-1.1.1-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (1.2 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

thorvg_python-1.1.1-py3-none-manylinux2014_s390x.manylinux_2_17_s390x.whl (1.3 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ s390x

thorvg_python-1.1.1-py3-none-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl (1.5 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ppc64le

thorvg_python-1.1.1-py3-none-manylinux2014_i686.manylinux_2_17_i686.whl (1.2 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ i686

thorvg_python-1.1.1-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (1.2 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

thorvg_python-1.1.1-py3-none-macosx_11_0_arm64.whl (995.0 kB view details)

Uploaded Python 3macOS 11.0+ ARM64

thorvg_python-1.1.1-py3-none-macosx_10_9_x86_64.whl (1.1 MB view details)

Uploaded Python 3macOS 10.9+ x86-64

thorvg_python-1.1.1-py3-none-macosx_10_9_universal2.whl (2.1 MB view details)

Uploaded Python 3macOS 10.9+ universal2 (ARM64, x86-64)

File details

Details for the file thorvg_python-1.1.1.tar.gz.

File metadata

  • Download URL: thorvg_python-1.1.1.tar.gz
  • Upload date:
  • Size: 76.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for thorvg_python-1.1.1.tar.gz
Algorithm Hash digest
SHA256 4757d6ef41b6d5bee49925b1578e18dce06b52d056e9e61c0a4a3b8740934039
MD5 25c77f06615fff3ee9dca81e9352738f
BLAKE2b-256 29cf3a4b544eb144444abcb9fcae1e61b0b8ec75a6b91f7d426ebc9d4d54a94d

See more details on using hashes here.

File details

Details for the file thorvg_python-1.1.1-py3-none-win_arm64.whl.

File metadata

File hashes

Hashes for thorvg_python-1.1.1-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 8fbd84e19c1dfd9e39e153f15e11700512b1b3b166ee82a89be5ac8131baa230
MD5 7b11019ef2271afc51037a72c7e1e38d
BLAKE2b-256 f041b6d616745dadb5e65820ff13298bb26040de7d793de11411a62bc0761449

See more details on using hashes here.

File details

Details for the file thorvg_python-1.1.1-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for thorvg_python-1.1.1-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 6864ab506798923afdd7b71e22761bd468e8af3561e3ec62a74cdf17d98d0d05
MD5 b94967330bf03b0c7380e10fa3c1335d
BLAKE2b-256 15579077d49aec8d9773510ad8a23066fa156416a1f87ccbc92f27cfbdfb2b0b

See more details on using hashes here.

File details

Details for the file thorvg_python-1.1.1-py3-none-win32.whl.

File metadata

  • Download URL: thorvg_python-1.1.1-py3-none-win32.whl
  • Upload date:
  • Size: 844.9 kB
  • Tags: Python 3, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for thorvg_python-1.1.1-py3-none-win32.whl
Algorithm Hash digest
SHA256 5383085df65aa63fa8103d3e260e37efb8c126ad18132b9c427121a6615888ed
MD5 d42252e84394f4605de05276016dfa91
BLAKE2b-256 2395dd1252d1fb9c913ca77654259529da433b305dfd30d2449399f2d56a3368

See more details on using hashes here.

File details

Details for the file thorvg_python-1.1.1-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for thorvg_python-1.1.1-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 9ee0ddd6f28f68f8c2dfa92743315a3afb05277895ab9ead7695a39ae5a3e8ec
MD5 d4ac1a750c5eade6de222981b075c54e
BLAKE2b-256 2106da6c4a96b5f8adf904e851b14a1028bf009767f19b679e8a204dc2faab1f

See more details on using hashes here.

File details

Details for the file thorvg_python-1.1.1-py3-none-manylinux2014_s390x.manylinux_2_17_s390x.whl.

File metadata

File hashes

Hashes for thorvg_python-1.1.1-py3-none-manylinux2014_s390x.manylinux_2_17_s390x.whl
Algorithm Hash digest
SHA256 cbbdd5f3de30f2a54cd4bccbc9746b6536600dc89b617941bb1cb5db358e0516
MD5 0b02d810be83ef9e8434bd082af19050
BLAKE2b-256 199192c5302a79e32639afa59475e0ceb1fd19813b7fae0a49ca45eda11445b8

See more details on using hashes here.

File details

Details for the file thorvg_python-1.1.1-py3-none-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl.

File metadata

File hashes

Hashes for thorvg_python-1.1.1-py3-none-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl
Algorithm Hash digest
SHA256 510bba922f2b657cb4a77fbd1b183ad6cc1dda33bb28471a2b979af5b4200d47
MD5 bb40a301274b50ec74004e6e229586cb
BLAKE2b-256 e308219fdda8ca2c7eb2a09c650fb7f01192e8aab473d965548a9350d0867040

See more details on using hashes here.

File details

Details for the file thorvg_python-1.1.1-py3-none-manylinux2014_i686.manylinux_2_17_i686.whl.

File metadata

File hashes

Hashes for thorvg_python-1.1.1-py3-none-manylinux2014_i686.manylinux_2_17_i686.whl
Algorithm Hash digest
SHA256 4b087584dba5bf97e2633d18aa5d731d0319dd4a53aba17fba7a3af4e9d63dd5
MD5 ca5db5408f70f4a53b43a7c65c3343b7
BLAKE2b-256 53077ac63b6e8c0cc0cef401d599e070b5ff34b03c0af6a51bb525d8ea5be378

See more details on using hashes here.

File details

Details for the file thorvg_python-1.1.1-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl.

File metadata

File hashes

Hashes for thorvg_python-1.1.1-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 c6d17a19fe42c25664276e8bd9b0a8772791754fd4c2655a76aa7371693b563b
MD5 3095e942cb492d62898603d6f0dd3ab7
BLAKE2b-256 874e701168145cc56686403d58386e16a2c82a33e0ae307caf9aec23d92c6faf

See more details on using hashes here.

File details

Details for the file thorvg_python-1.1.1-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for thorvg_python-1.1.1-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 61d7c4747ca78d7de8ec9534ba42059c9ceffab2caa9d939521edea1778fd916
MD5 69431d8b61a17f4537792343f67f7d7f
BLAKE2b-256 90ba616386e29fd705dcdfecdc16777aabb09797ac38986aecbfaf4f6c5d766a

See more details on using hashes here.

File details

Details for the file thorvg_python-1.1.1-py3-none-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for thorvg_python-1.1.1-py3-none-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 0d5ad6262b47f288bdf60f4d9eea307ab7db52e03e11a4e7213034431e16715f
MD5 3536af24ad31806be87a476b79e9e057
BLAKE2b-256 0a5fe0cad64ee7ca1ac3f3dd93c6e8657cd31bd9b805768006e1a58958c8e0b8

See more details on using hashes here.

File details

Details for the file thorvg_python-1.1.1-py3-none-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for thorvg_python-1.1.1-py3-none-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 c09b3b1dcd600cd0e2ed1812553ce6513b81ef757120b83f91b4c91362374e71
MD5 c612990d583fc869f53e00562ad1aa84
BLAKE2b-256 dbb2c250ccbbd7b8f3d10fa16f0dffb0d11d705c5f86998ff661d6c98f1680ed

See more details on using hashes here.

Supported by

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