Skip to main content

No project description provided

Project description

resvg-py

title

Resvg-py is a Python package that provides high-performance SVG rendering by wrapping the resvg Rust library using PyO3. This package allows Python applications to easily render SVG files to various image formats with high fidelity and performance.

See https://github.com/RazrFalcon/resvg for more info about resvg.

This project is inspired by https://github.com/yisibl/resvg-js. The image credits mentioned above also go to the same source.

Installation

pip install resvg affine

Usage

Here's a simple example of how to use resvg-py to convert an SVG file to a PNG image:

from resvg import render, usvg
import affine

with open("a.svg", "r") as f:
    svg = f.read()

db = usvg.FontDatabase.default()
db.load_system_fonts()

options = usvg.Options.default()
options.font_family = "Space Mono"

tree = usvg.Tree.from_str(svg, options, db)
tr = Affine.identity()
data = render(tree, tr[0:6])

with open("a.png", "wb") as out:
    out.write(bytes(data))

File content of a.svg

<svg width="600" height="300" xmlns="http://www.w3.org/2000/svg"
  xmlns:xlink="http://www.w3.org/1999/xlink">
  <defs>
    <linearGradient x1="0%" y1="45%" x2="100%" y2="55%" id="b">
      <stop stop-color="#FF8253" offset="0%" />
      <stop stop-color="#DA1BC6" offset="100%" />
    </linearGradient>
    <path id="a" d="M0 0h600v300H0z" />
  </defs>
  <g fill="none" fill-rule="evenodd">
    <use fill="url(#b)" xlink:href="#a" />
    <text x="50%" y="39%" font-size="58" fill="#FFF" dominant-baseline="middle" text-anchor="middle">Hello
      resvg-py</text>
    <text x="50%" y="62%" font-size="38" fill="#FFF" dominant-baseline="middle" text-anchor="middle">高性能
      SVG 渲染引擎和工具包</text>
  </g>
</svg>

Affine Transformation

The resvg-py package utilizes the affine library for the convenient creation of affine transformation matrices, thereby eliminating the need to directly wrap the Transformation class from tiny_skia.

It's important to note that when providing a 6-element tuple as the second parameter to the render() function, this tuple should be in row-major format. This detail is crucial for those who might calculate the transformation matrix using other methods or libraries before passing it to resvg-py.

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

resvg-0.1.0.tar.gz (60.8 kB view details)

Uploaded Source

Built Distribution

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

resvg-0.1.0-cp310-cp310-macosx_11_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file resvg-0.1.0.tar.gz.

File metadata

  • Download URL: resvg-0.1.0.tar.gz
  • Upload date:
  • Size: 60.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.4.0

File hashes

Hashes for resvg-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d99ba9199e356c4da16441822148c47c8031911d45fdff9b45d20f869092c136
MD5 5e98ff7dab680117f6b370a6bf0dd84c
BLAKE2b-256 0534b8bae716d3e8d9905ed13a689c463ca93df8fe2d16d11f2e306b8de04d12

See more details on using hashes here.

File details

Details for the file resvg-0.1.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for resvg-0.1.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ee75852695d3f7ced7e5fa9186acf9da7c854f04f8996a48c8f2adec206f110c
MD5 6bc94e8710f7b4265940f4a4c0359284
BLAKE2b-256 7d02b67e697fe107251db3d134ba33b12e813b6879c792176cef6ce3e08f04cf

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