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

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.3.tar.gz (78.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.3-py3-none-win_arm64.whl (855.7 kB view details)

Uploaded Python 3Windows ARM64

thorvg_python-1.1.3-py3-none-win_amd64.whl (969.1 kB view details)

Uploaded Python 3Windows x86-64

thorvg_python-1.1.3-py3-none-win32.whl (853.6 kB view details)

Uploaded Python 3Windows x86

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

Uploaded Python 3macOS 11.0+ ARM64

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

Uploaded Python 3macOS 10.9+ x86-64

thorvg_python-1.1.3-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.3.tar.gz.

File metadata

  • Download URL: thorvg_python-1.1.3.tar.gz
  • Upload date:
  • Size: 78.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.3.tar.gz
Algorithm Hash digest
SHA256 9d1c0dcacc58208fb5001390944c4547299b46e6fb50b147363a40f678fbc620
MD5 ebeb85622855ea20d4cfe00d76db1b2d
BLAKE2b-256 f75ea421ce26828cf04bd9a7862ff7fb0011a6bb19ffcdf768e31c392338184c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thorvg_python-1.1.3-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 4eba0ebb9f7529df7a31735716b6ff4c8e2126ec8942ae0f7aca4f3ce45294d7
MD5 41d67f285d056799625b2fb2bd80fe85
BLAKE2b-256 0be2e7bfa56233ebf01d01b2479d2c5adbeda96e8fc50d7f4cbb78fe3a9faaf1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thorvg_python-1.1.3-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 305671f651d2e455d241c8704636f2061be86cdb80a6743cf6d7dce6bcca1c5a
MD5 f774fc7e42936f8bcb0eabde7ab6a157
BLAKE2b-256 3d9f99902c58bda2082dea9687fe0aa75992429a9adbe2e5d82a729859641016

See more details on using hashes here.

File details

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

File metadata

  • Download URL: thorvg_python-1.1.3-py3-none-win32.whl
  • Upload date:
  • Size: 853.6 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.3-py3-none-win32.whl
Algorithm Hash digest
SHA256 2794128d3ec6c4e90f969d83b3f97a7a33e36ab794ba6e6c86710d86400e884e
MD5 6b33422116a122671bd7805f7b8b8007
BLAKE2b-256 4c21e0db08c2d299b15120d9d61063ec1f3c1d8e2f195316df532ac833489c14

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thorvg_python-1.1.3-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 0c2efd705bf7badd08b8f6e60696cb87fe908c9a04aa3b0352430aead00db33a
MD5 e9d38a47640e3dc7ac9463ff3e34d7f7
BLAKE2b-256 b16eed45f8cf23c6edc62865053141d0c8f16f5cad9b3aaa74fa7a8528355ed4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thorvg_python-1.1.3-py3-none-manylinux2014_s390x.manylinux_2_17_s390x.whl
Algorithm Hash digest
SHA256 fad03d766a4e17f8ba544dfe78a99a12e059b9cc5ff515b6a40eef2c7a5024c3
MD5 7bbc99fb9a930fa2c46743af6ea694bb
BLAKE2b-256 6e88b7b32b2fbdf6d99c23cd73d5c16317629ed23d7c0a7ca585352be448044d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thorvg_python-1.1.3-py3-none-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl
Algorithm Hash digest
SHA256 bafc7bd3747c89de60926ce1e8a4ade2efe2ac98f4edc134b0974d8d5fb98ce5
MD5 93bbd42cf0848c57c2a51ca46a7e97d5
BLAKE2b-256 0aafb2b006977a8bfe123af986dc291edc0df654b5e3337047eb6448648b2c6c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thorvg_python-1.1.3-py3-none-manylinux2014_i686.manylinux_2_17_i686.whl
Algorithm Hash digest
SHA256 6fffadda3a391044d3435cf14a446c78b3e0acc7fc4a4c1e88b4ff76207dca95
MD5 a5e4333add069521f321f3ed73d932e6
BLAKE2b-256 d318e98658d9fce37a9e2c040a7dc0b051652510afa0ed7d201681f26d9fdd7c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thorvg_python-1.1.3-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 3e8baf4df97be90c449bda9eff9b85749f32034abaa046fb0ad5a13f3e1eba88
MD5 3ba77bbf69191d70554b2977318b15fe
BLAKE2b-256 ff197386a857588ebabe8d3eee8b52a1e59ad6f12ece0b2728f5e6e949214cd9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thorvg_python-1.1.3-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 340fc8862e87e6071a26ae9d6d5e0e8acbc9aa8c2f39a038095f79d5cae60dbf
MD5 457e7c12836a6fe3b1c021063bcee28a
BLAKE2b-256 382b22418f0e626c8d585cc113176073a8e51b52979625aaff8bdc2c35073d0e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thorvg_python-1.1.3-py3-none-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 56adc0159e331ce5879760d4606be0e25da74387240207a48375b9b757d81b5a
MD5 6f32a6554c66a9ce714d67a8d28e25f4
BLAKE2b-256 346ca4d8e611ce8ad88878d241f08c216cbd944f7f953a744fbb96c3aa0fdd5c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thorvg_python-1.1.3-py3-none-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 f38141f14410c0991b8ac08db74850c6baf31a1ec45870ed74d65fdd6e02ac43
MD5 cda286a0cd891745818baee433e9c8fd
BLAKE2b-256 1ed134b044fe29d49b47f9460fbe6715bf23009c5bf3632c6a104b5df8584f57

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