Problem with cairo, vg and myself

Hello,

I’m working on a small server where I want to render an image as PNG and serve it as a mime png.

I used cairo and vg and got pretty far drawing dots, squares and positioning them, even fonts, but now I wanted to “load” an image into the png.

I thought I could have a buffer, and render any image and move them accordingly as any other Vg.I, at this point I started reading the documentation and didn’t get any far.

So, after opening this issue Multiple Images · Issue #30 · dbuenzli/vg · GitHub I opening this post here to fix my head around this.

If I understand correctly: If I want to read the data of a filename I should use Cairo.PNG.create and this gives me back a surface, then create another surface with empty data, create 2 contexts and somehow merge the renderables? But then, I have no way to position the image with Vg.I and I need to do it with Cairo.move_to. I suspect that isn’t the best way to load an image.

PS: Apologies if the terminology is off, I feel like the definitions require a good knowledge of Cairo already, which I don’t have.

Thanks in advance!

In an ideal world Vg would support raster images. Unfortunately I never got the time to do it. If someone’s interested in funding this, get in touch.

I think you are on the right track though. Simply draw in your Cairo context as you wish using the Cairo API (for drawing a PNG image see this example) and before or after render the Vg image using Vg. The exact effects performed on the context by Vg’s renderer are described here.

1 Like