Skip to content

Draw polygons using libvips #3560

Answered by jcupitt
ido-nuc asked this question in Q&A
Jul 10, 2023 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

Hi @ido-nuc,

The simplest solution is just to draw them with SVG:

import pyvips

x = pyvips.Image.svgload_buffer(b"""
    <svg viewBox="0 0 200 200">
      <circle r="100" cx="100" cy="100" fill="#900"/>
    </svg>
""")

x.write_to_file("x.png")

To make:

The SVG loader is progressive, so it can draw SVGs of any size (up to 32k x 32k pixels) using only a modest amount of memory. You can make masks by just taking the alpha, you can combine masks with the boolean operators, and you can render stacks of RGBA images with composite.

The 32k pixel limit is unfortunate :( It comes from cairo, sadly, and isn't really fixable. We are considering switching to another SVG renderer, but no one's done…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@lejsekt
Comment options

Answer selected by ido-nuc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants