Draw polygon using pyvips example
Hey, 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!
Please help. Thanks in advance!
Hello @aravind3134,
You can draw anything with SVG, for example:
import pyvips
x = pyvips.Image.svgload_buffer(b"""
<svg viewBox="0 0 100 100">
<circle r="15" cx="50" cy="18" fill="#900"/>
</svg>
""")
x.write_to_file("x.png")
It can draw any size image and it's pretty quick. Use the boolean operators, or perhaps composite, to layer or mask another image.
Hey John, Thanks for the quick response.
I tried to run the code snippet that you sent me. I am facing issues with it. Looks like it cannot find the function.
I get the following error. I am using version 2.1.8
pyvips.error.Error: no such operation svgload_buffer VipsOperation: class "svgload_buffer" not found
Your libvips has been built without librsvg. You'll need to install librsvg-dev and rebuild it.
I couldn't install this in conda or pip.
However, I tried installing conda install librsvg and it worked fine with installation but says segmentation fault (core dumped) when trying to run the same code.
import pyvips
print(pyvips.__version__)
x = pyvips.Image.svgload_buffer(b"""
<svg viewBox="0 0 100 100">
<circle r="15" cx="50" cy="18" fill="#900"/>
</svg>
""")
x.write_to_file("x.png")
Is this fine? If not, should I be removing pyvips and libvips completely. Please guide me as I am new to this library.
Thank you.
It won't work in conda.
Anaconda is a different world and nothing works properly unless there's an official conda package. You need to switch to standard Python, or wait for conda to support libvips.
So, if I have used conda to create the environment and if I use "pip install librsvg-dev". Will it work?
I tried but it didn't work. Can you please explain me the requirements to install it, including the command to be entered on the linux terminal?
Thanks.
Is this Ubuntu? Just sudo apt install libvips-dev, then pip3 install pyvips. Don't use conda! Uninstall it, and everything related to it.
Alternatively, I'm trying to make a libvips package for conda. It should be ready in a week or two, and then pyvips might work there too.
The issue is being tracked here:
https://github.com/conda-forge/staged-recipes/pull/8912