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.0.tar.gz (1.2 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.1.0-py3-none-win_arm64.whl (845.3 kB view details)

Uploaded Python 3Windows ARM64

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

Uploaded Python 3Windows x86-64

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

Uploaded Python 3Windows x86

thorvg_python-1.1.0-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.0-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.0-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.0-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.0-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.0-py3-none-macosx_11_0_arm64.whl (995.0 kB view details)

Uploaded Python 3macOS 11.0+ ARM64

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

Uploaded Python 3macOS 10.9+ x86-64

thorvg_python-1.1.0-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.0.tar.gz.

File metadata

  • Download URL: thorvg_python-1.1.0.tar.gz
  • Upload date:
  • Size: 1.2 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.1.0.tar.gz
Algorithm Hash digest
SHA256 42961d9ea0971bbeaafc103d8350b4575b6fa73ab521fdc520bc0a0d88c0b22b
MD5 35c92d33dd7079ccdf0b5183d5bd2163
BLAKE2b-256 aeb4f7264ef9648c818b4b42824196819c2115c88dd8009dafd8a391cc6f3980

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thorvg_python-1.1.0-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 11ecc917f13dbfe38970e727e26822885c49fafe4f8ff3cd88fd1033a8c2640e
MD5 f2740b240bb6748c1df21e36341efdd6
BLAKE2b-256 3ae875c677b202ce6dbf50888c6f9e02c4590893ccc7536df4d83e835cb18c8a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thorvg_python-1.1.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 b2a9f3bea75f5eaf6ca0bc027939e08aeb569325ed2c3b14995012c234ba600b
MD5 789eac95b157c809448cd2a0e3eecf6b
BLAKE2b-256 4b41f139663ad56800071f979599ddae3938b05d69b08528b8496a1b4401986a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: thorvg_python-1.1.0-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.0-py3-none-win32.whl
Algorithm Hash digest
SHA256 3babd230833e12b3a70ea0160f48aee7173416fab94e2797e3cd28ad6b72d2f5
MD5 88b9ab13103eb481d36477e2997b4015
BLAKE2b-256 0261623cf8224d3bbdb2eb4d0f6f00ac923de6dc8822c6294e218ec9ebf4fd92

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thorvg_python-1.1.0-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 0a9da50801a0f84eb49c6072a3be7c937d092afb44a4ed282e97670645884007
MD5 a520b3746082acd288eb1e1065d1f344
BLAKE2b-256 bc4d3e9ada2fc9bf99d2c251197622f8c824ec5f512d3e913cf86f7b7e0740f3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thorvg_python-1.1.0-py3-none-manylinux2014_s390x.manylinux_2_17_s390x.whl
Algorithm Hash digest
SHA256 8bb3320721e59eec9d004024213660b36e6317b2c8cd8b165806bd79d36cfcca
MD5 e18a73c9689ce24977f97b84949d5281
BLAKE2b-256 06da861812c7bf6d74094efb80ed394f98d3b9172c654f241ed5631521de5d5d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thorvg_python-1.1.0-py3-none-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl
Algorithm Hash digest
SHA256 720edbf006d200928342131029c65dc2711295f7e50caca76fbbf46623c47e06
MD5 5d908838b8d640559051a15d330049d7
BLAKE2b-256 c068df785a0b0ef78b1e4cebe63ba2e52ccc466b77568428108b3798f1bd78d1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thorvg_python-1.1.0-py3-none-manylinux2014_i686.manylinux_2_17_i686.whl
Algorithm Hash digest
SHA256 acd8bc0d8f0102492ec29b8a452bd8369ff0a873b2c7e9082cb2c7f90cc98c32
MD5 f88c6edfaeeda528282cc4990c8c638d
BLAKE2b-256 ccb41fab557026e4e4b33b463bb0a729ad61d56af2ddb042ecaa761d4e9baf69

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thorvg_python-1.1.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 ac5b25b0bd8d5671bbbd0c73b8a9b697c809160e95167e2f5514e858224afde7
MD5 72e464e808ed9b74ba7f19a1525ac82b
BLAKE2b-256 d4e5942649db8cf76afd29894b58dbdf869f2704f977a46af39603db3f218224

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thorvg_python-1.1.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5a19c115268f77966f5837a922fb1325cdb45018545d3ddaaa617410ce0a9439
MD5 0dd3cacfe37a9678f34af7a111512de2
BLAKE2b-256 01b7f0b955b93175c048512e396d8400e6885f868a7e007bd83130ab6ee15f97

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thorvg_python-1.1.0-py3-none-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 5a03207761f014192cbbdf156cb80a01a85b5bbf1b57e02d0727161d06f9a642
MD5 1cc9c10539404b041d3b3ce46ccb8d3e
BLAKE2b-256 cd4a8edc497e30075ef2458d4bb16ab02ab01ab2dc3b7573477a306ce75da4a7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thorvg_python-1.1.0-py3-none-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 696519f5aeec1cc0b44e237585739309a8e12c9e26c1851f1a2b6a547ba60a49
MD5 a185cc6586a35c570fc0ab9fb2e2cb09
BLAKE2b-256 45894540f712ee462841d988b0bbedecb1059d633281f2520b7779c0345de819

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