You probably aren’t doing this in HTML 5 canvas but if you were there’s a method for discerning the width of text as it would be rendered.
But in most apps you can’t do this. You’d have to find and process font metrics for whichever font you’re using.
However, there is a very naive method: Pretend the font has fixed width characters and count them, multiplying the let’s-pretend width by the number of characters. (Then add a few characters’ width for safety.) Yeuch!
I'm doing this in Keyboard Maestro using "composite text onto image" action. Hence my reasoning for coming here to ask
FWIW, I know font metrics, CoreText is like a second language to me.
The question is a Keyboard Maestro question.
I am generating those images using Keyboard Maestro's composite text on image action, I was just wondering if there is a way to composite onto, say, a blank canvas, and clip / crop to the bounds of the non-alpha, and measure the result, within keyboard maestro. I know I can do it using ImageMagik or other utilities, but I thought maybe there is a built-in way to do it in KM that I'm missing.
The answer is to 'composite' the text into a temporary canvas (made of a transparent color) and use KM's 'trim' image to crop off the all the non-opaque pixels, then use 'get image width' to get the width
It's for a report I send out once per day. Side note, I actually adjust the colors because one of the guys on my team is color-blind, and the original colors / legend for the chart doesn't work, so I screenshot the chart, pad the top and add my own legend all using KM. Not sure what KM uses behind the scenes for image manipulation, but it's REALLY fast (FWIW).
Second side note: For any developers out there writing software, PLEASE remember to provide accessible - alternative layouts for folks who are color blind, such as charts with different shape bullets, etc...