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.3)

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, True)  # x, y, w, h, rx, ry, clockwise
rect.set_fill_color(32, 64, 128, 100)  # r, g, b, a
canvas.add(rect)

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

im = canvas.get_pillow()
im.save("test.png")
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.2.tar.gz (77.6 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.2-py3-none-win_arm64.whl (851.8 kB view details)

Uploaded Python 3Windows ARM64

thorvg_python-1.1.2-py3-none-win_amd64.whl (964.1 kB view details)

Uploaded Python 3Windows x86-64

thorvg_python-1.1.2-py3-none-win32.whl (850.1 kB view details)

Uploaded Python 3Windows x86

thorvg_python-1.1.2-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.2-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.2-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.2-py3-none-manylinux2014_i686.manylinux_2_17_i686.whl (1.3 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ i686

thorvg_python-1.1.2-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.2-py3-none-macosx_11_0_arm64.whl (1.0 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

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

Uploaded Python 3macOS 10.9+ x86-64

thorvg_python-1.1.2-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.2.tar.gz.

File metadata

  • Download URL: thorvg_python-1.1.2.tar.gz
  • Upload date:
  • Size: 77.6 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.2.tar.gz
Algorithm Hash digest
SHA256 1c48cc5acb64225f2ef0d04886d097dd61828eed50e06a0e20c9200867d718d4
MD5 66a5b6ca6a00673fe19548221934ee3a
BLAKE2b-256 ac570a3a345a91d6a4c2623f570d3dd9de8613cc88c4929a7cf3183d9482241a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thorvg_python-1.1.2-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 030cf44026d558cd194f755e242b5fd8132eb5397283a07a735642c329a190a3
MD5 7fd398983f2753588b2e58ed8ae775eb
BLAKE2b-256 aa9e71d0c3832c2f0a4a0f7b5054c5c73d14f09d4dd4134cdbc63c9b307b015e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thorvg_python-1.1.2-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 e3fccd2c888b7787b2e9bff7c07fcdacf388d1821d7edfb787325d6422802d3c
MD5 0db356e9951331a7a45e194adf915444
BLAKE2b-256 9827e09e7e01b3ea3c340750b65792552711ec6013cbe118d64d20afa1de1082

See more details on using hashes here.

File details

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

File metadata

  • Download URL: thorvg_python-1.1.2-py3-none-win32.whl
  • Upload date:
  • Size: 850.1 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.2-py3-none-win32.whl
Algorithm Hash digest
SHA256 68b0e3ca790289ed07768200371b316862570434592ed2a15edb40752625ae33
MD5 8dd8523dbae925c3b7d6f54ec7af2f77
BLAKE2b-256 8e5656f5a46a3c27798e2f7cc0d12fcb3c91a1a9d13d360b55157f7b167e4cac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thorvg_python-1.1.2-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 28a03b648b4d77a31224741716d20127f6cf571d88669358872d05d65e142bc8
MD5 984a089cedb6b31c677c1ea2a77f704c
BLAKE2b-256 22173c2fedec09a01bd9cccf33c74f8d69cbe34b3cdf7538f7e359fb63c046db

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thorvg_python-1.1.2-py3-none-manylinux2014_s390x.manylinux_2_17_s390x.whl
Algorithm Hash digest
SHA256 c496d247f7408a3091d5b3e0a9cc6a01c0b296705a4add8184fee8cda9acf9d1
MD5 566c20fd598b43f27b193831d1203bb4
BLAKE2b-256 6c0846387c8acbed58588bc868b6897b5acf4bb40cf171aca7f3e33baacd6584

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thorvg_python-1.1.2-py3-none-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl
Algorithm Hash digest
SHA256 a3a244de6c7051aedb18c50a8b10387144910609cf5eefceb7b6e1619be7d8e4
MD5 9db661951aa4abad081fe4318b6fb6d2
BLAKE2b-256 81d8905ae8cab4eca3e54f2a6ae448885c4e73001ef29f085aa93562d9b7202f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thorvg_python-1.1.2-py3-none-manylinux2014_i686.manylinux_2_17_i686.whl
Algorithm Hash digest
SHA256 17b9a24dc2d58bcf15b7471783f07867fe275448f7fb87214f058b83bd7321fb
MD5 f77e17a27c296da8e4e4d60f361d4bb3
BLAKE2b-256 07671488366821843c0a734152e3b4052f9679263bf06201f6e1baae58c3435c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thorvg_python-1.1.2-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 e13e2805db221c46654926bf5f3f09b2a744583d493ce1ec9637b547496d2535
MD5 a6c4b137c731b4a271d2f528cc4cda2a
BLAKE2b-256 f8a92e71a459e1a9f239e8038b0035546763def8813344b08ca4c9e752ab814d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thorvg_python-1.1.2-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3dd1e898b2071122f879e0cd83e3c8a520fab8a82cca24d20a1215c650e0499e
MD5 ffe6cf863a68516c586892090e20fb01
BLAKE2b-256 5e708fc429a9142ded504968256d22c5cad8d2644860000458266dfe4d927940

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thorvg_python-1.1.2-py3-none-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 47d5e4f9301cc7f673b9857f84dc9717704479a1bb064f8a97356e3d0306d872
MD5 9ea1d59c1e879c18056345e7678f8f35
BLAKE2b-256 001cb69f8d21022b2bbcf4c06719bba685898933e8642a5d8f9df52568961234

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thorvg_python-1.1.2-py3-none-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 0f70322af0762af53cb168e321941395aae57e4c5db08de682d10b11d2dde312
MD5 a0863a75e599fd546569faf54e809c4e
BLAKE2b-256 4ab67fc7e97b8eb5cd941a5e3617c25db5ff084ddd641001ae22ad9f7fa190ce

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