Copy link to clipboard
Copied
I would like to measure the width of a given word or words (not a paragraph) when rendered with a given font and font size. Let's say I have the code below that creates a new document, layer, and text:
var myDoc = app.documents.add(200, 200);
var textLayer = myDoc.artLayers.add();
textLayer.kind = LayerKind.TEXT;
var text = textLayer.textItem;
text.font = "Impact";
text.size = 72;
text.position = Array(100,100);
text.contents = "SUPER";
I want to measure the width of text
.
Ultimately I want to resize the text to be a certain width while maintaining its aspect ratio. (The height of the text is not important, just the width, and it should not be distorted.) Knowing the width I could easily calculate the correct font size. If there is a better way to this solution than measuring the width, please let me know.
Thanks!
The layer has a property "bounds" from which you can calculate the width.
var width = textLayer.bounds[2] - textLayer.bounds[0];
Copy link to clipboard
Copied
The layer has a property "bounds" from which you can calculate the width.
var width = textLayer.bounds[2] - textLayer.bounds[0];
Copy link to clipboard
Copied
There is no relationship between point/pixel size and character width…
I don't think there is an alternative to set, measure and calculate…
Copy link to clipboard
Copied
And what's about "resize the text to be a certain width while maintaining its aspect ratio"?
Copy link to clipboard
Copied
What about it?
Copy link to clipboard
Copied
How is it possible change width of text to fit desired width?
Copy link to clipboard
Copied
Calculate the necessary point size or transform.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now