1

I want to draw a polygon/polyline on to a big image.

So, I am migrating from PIL/opencv to pyvips. Recently, I came across loadsvg_buffer method that can actually do it without the use of draw_mask and draw_image methods.

Can someone give me one fill example using loadsvg_buffer or draw_mask or draw_image. The documentation wasn't much helpful.

Also, what if I have to draw multiple polylines?

Any other insights are welcome.

Nakilon
  • 34,866
  • 14
  • 107
  • 142
Aravind
  • 54
  • 6

1 Answers1

3

svgload docs are here:

https://libvips.github.io/libvips/API/current/VipsForeignSave.html#vips-svgload

You can draw any SVG figure. For example:

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 generate:

red circle

The libvips SVG loader is very fast and can make images of any size. It renders progressively, so it doesn't need much memory either.

Use the boolean operators to mask other images with the result, or use composite to layer images together with the PDF blend modes.

jcupitt
  • 10,213
  • 2
  • 23
  • 39