Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bounding box of an image #37

Open
damien-pous opened this issue Mar 14, 2024 · 2 comments
Open

bounding box of an image #37

damien-pous opened this issue Mar 14, 2024 · 2 comments
Labels

Comments

@damien-pous
Copy link

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:

  • being able to align/center text (by calling cut_glyphs, and then using the box of the resulting image to place it correctly)
  • being able to export optimally cropped pdfs (without having to keep track of the bounding box by myself, which is delicate when Bezier curves are involved, etc...)

Best,
Damien

@damien-pous
Copy link
Author

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

@dbuenzli
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants