Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to measure/scale text to fit desired width?

Guest
Jul 10, 2014 Jul 10, 2014

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!

TOPICS
Actions and scripting
2.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 11, 2014 Jul 11, 2014

The layer has a property "bounds" from which you can calculate the width.

var width = textLayer.bounds[2] - textLayer.bounds[0];

Translate
Adobe
Community Expert ,
Jul 11, 2014 Jul 11, 2014

The layer has a property "bounds" from which you can calculate the width.

var width = textLayer.bounds[2] - textLayer.bounds[0];

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jul 11, 2014 Jul 11, 2014

There is no relationship between point/pixel size and character width…

I don't think there is an alternative to set, measure and calculate…

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 08, 2017 Oct 08, 2017

And what's about  "resize the text to be a certain width while maintaining its aspect ratio"?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 08, 2017 Oct 08, 2017

What about it?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 08, 2017 Oct 08, 2017

How is it possible change width of text to fit desired width?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 08, 2017 Oct 08, 2017
LATEST

Calculate the necessary point size or transform.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines