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 0.15.16)

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()
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()
    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.0.1.tar.gz (1.1 MB 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.0.1-py3-none-win_arm64.whl (850.3 kB view details)

Uploaded Python 3Windows ARM64

thorvg_python-1.0.1-py3-none-win_amd64.whl (965.2 kB view details)

Uploaded Python 3Windows x86-64

thorvg_python-1.0.1-py3-none-win32.whl (851.0 kB view details)

Uploaded Python 3Windows x86

thorvg_python-1.0.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.0.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.0.1-py3-none-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl (1.4 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ppc64le

thorvg_python-1.0.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.0.1-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (1.1 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

thorvg_python-1.0.1-py3-none-macosx_11_0_arm64.whl (972.9 kB view details)

Uploaded Python 3macOS 11.0+ ARM64

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

Uploaded Python 3macOS 10.9+ x86-64

thorvg_python-1.0.1-py3-none-macosx_10_9_universal2.whl (2.0 MB view details)

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

File details

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

File metadata

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

File hashes

Hashes for thorvg_python-1.0.1.tar.gz
Algorithm Hash digest
SHA256 7ef43fd08deab9a10a67da8e5d3999e6d04c067af4a58e9673f76782e1073edc
MD5 f5ae2c1df94c8ef62dce0a15573dbcf8
BLAKE2b-256 c634327ea1843388f97179284614202b17ee19559d76ff20b0e2a01d9ea4bd3b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thorvg_python-1.0.1-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 0e77b22fc51c9f92e81a4be7b1fbd3cb9732b56a7c36e3b6d236b1fd00b29bd3
MD5 2cad5faa4467f54063d41f5c36d8ee77
BLAKE2b-256 4b398b2df7db7c38ca7c13e99c5e48d7deb108bcb2a294f0baac53e225e361f6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thorvg_python-1.0.1-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 d3e27d455f15ef00517c1d010e892e44f962b01c89d8871d06ed5bea5bc55106
MD5 84c02ee6297d461113c5f65018ee74d5
BLAKE2b-256 74e5c6ae4812c134fa599daef5ad07a15a446b51702f7f8a5710a805d17359f7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: thorvg_python-1.0.1-py3-none-win32.whl
  • Upload date:
  • Size: 851.0 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.0.1-py3-none-win32.whl
Algorithm Hash digest
SHA256 5054939f6a0f468a97f01891b38c7fac5ed13f3bdf3a1c1ebaba60c4d859e797
MD5 03568ddaaa5020a8cf6290fe5dcbeb3e
BLAKE2b-256 acc2462b2bec915f13b05fa0b8139edb2c736dbd0ac1048eb771da014431be0f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thorvg_python-1.0.1-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 4a575f487615f460f48c8e40afe821c0a9e340bd1ded78550b21f15c59bb885d
MD5 89da2a48155f6d5a4d7de53124c8884f
BLAKE2b-256 7ae868a6f2674e8286b9629dee3269947d7436d1228965e875d037bff59f1011

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thorvg_python-1.0.1-py3-none-manylinux2014_s390x.manylinux_2_17_s390x.whl
Algorithm Hash digest
SHA256 ba913147b023b00c6ad3a3ef92628cf6f9bbf6836466874cee929b28f2db6494
MD5 297e3fd1928cef195c196af69b0fdecb
BLAKE2b-256 b90857b477e97728a649a64800444ed3977f3c763ff4369946cfafa834caae0b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thorvg_python-1.0.1-py3-none-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl
Algorithm Hash digest
SHA256 188e409ea97856a7915607a8d2753b448b246221d0c6aff1e10d5d7ee273a77a
MD5 3533dc3828367fcf2d61d8e1b0b3f0d5
BLAKE2b-256 614e86c2c73b2bdb4758500aeb3b958ad7335f968a3d143f8a559e0b8e426041

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thorvg_python-1.0.1-py3-none-manylinux2014_i686.manylinux_2_17_i686.whl
Algorithm Hash digest
SHA256 40f7ac3de93936fcac72e96d2f5b54740f397fe9ddc507588e24060bc74618b0
MD5 e223507eeead62dc679e12d8a1777764
BLAKE2b-256 90b96ef093921c89e843ee7a71b11e6faeb79015b01b4adf175b9ac1cfd5d5bf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thorvg_python-1.0.1-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 ca890638a1de7e3f7d2475bdd02bfa1597524278c4e5b528e863f04194ad2d40
MD5 6f1ff3483e97646a83f9e0b5f895368c
BLAKE2b-256 9aaebe7faba5ab32a35ff4128be342bd32cab851945812fa9263035b18e8afc6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thorvg_python-1.0.1-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0df5de992271fd4ffb60ebfb630366c92ce841574a818720a89ff17c11a87c1b
MD5 43934f9d8951ef122b32828e5fe1cbd1
BLAKE2b-256 d8629690f2dd1164dc81960369b53c160d6a87b5135ca2ca539212e65a0b5abf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thorvg_python-1.0.1-py3-none-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 35cf7ccdcc2170d80cd3d23a49993301b29b886300babf1063a632dfa9713824
MD5 f3c9280c8a7b15c54ca2c9c1cd792248
BLAKE2b-256 ea439d2d3d481611e18d01cc8d57c5d0943e0856efaa51bc317e68c594bc3dcf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thorvg_python-1.0.1-py3-none-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 a9977d9145213b04d26971c7f5219cddf9b2d27bba1fec64996ccf4be1787bb0
MD5 7c7e7bc124bb9307a7b8bc643380dd87
BLAKE2b-256 746184049b28528c2bf737c7c9a17ac8e8e052f2245ed33e6e1ed6dc4c123076

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