dbuenzli / vg

Declarative 2D vector graphics for OCaml
http://erratique.ch/software/vg
ISC License
91 stars 12 forks source link

bounding box of an image #37

Open damien-pous opened 8 months ago

damien-pous commented 8 months ago

Hi,

First of all, thanks for this nice library!

I'm wondering if there is (or could be) a way to compute the "bounding box" of an image. I.e., the least box (if any), such that the image is void outside of the box. Possibly you would argue that this defeats the concept of "infinite" image, but I would find it useful for two things:

Best, Damien

damien-pous commented 8 months ago

(for the first point, some access to a function like Cairo.text_extents would be an alternative)

dbuenzli commented 8 months ago

Vg is a low level API so it doesn't provide these things (see here about measuring text). In general you'd want to add more structure to keep track of these things.

For your second point, you could perhaps simply try to compute one based on the representation provided for renderers see here. If you get to something we could consider integrating it.