#๐ Is it possible to calculate this?
23 messages ยท Page 1 of 1 (latest)
@white beacon
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
You'd need to know the width of each character.
unless it's fixed-width
hah, I was just going to suggest PIL.
Really the best way is to render it first and measure it.
as far as I know
it's not a trivial problem fwiw
It's a difficult problem to solve. Fonts are very complex.
For example: ligatures make life hell: https://fonts.google.com/knowledge/glossary/ligature
But rendering and measuring is probably a viable strategy: but then you may run into os related differences in rendering.
i personally used pygame for font rendering and checking. pygame has functions that return the width,height of a given text with given font and size without rendering it
Monospaced fonts make this easier
@white beacon What is your application doing with the strings? It may be better/easier to just force a certain string length with a good margin.
with most non-monospace fonts, that would lead into a very ugly result
fair
depends on the application
Have you seen https://imgflip.com/memegenerator ?
Insanely fast, mobile-friendly meme generator. Caption memes or upload your own images to make custom memes
I think it's doing what you are trying to do
That site dynamically resizes the text area depending on the length of the input string.
(so it fits inside a bounding box)
Yup, so a crude answer is to just come up with an estimate that errs on the side of caution
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.