I am using Extendscript for Photoshop CS5 to change the text of a text layer. Is there a way of checking whether the text fits e.g. by checking whether it overflows after changing the content?
I am using Extendscript for Photoshop CS5 to change the text of a text layer. Is there a way of checking whether the text fits e.g. by checking whether it overflows after changing the content?
2
Answers
I haven’t found a way to do this directly. But I’ve used the following technique to determine the height I needed for a textbox (I wanted to keep the width constant) before.
Totally roundabout – but it did work.
I created a solution that works perfectly fine :). Maybe someone else can use it as well. Let me know if it works for you too!
How to use / Explanation
scaleTextToFitBox(textLayer);
The function will change the text/font size until the text fits inside the box (so that no text is invisible)!
The script decreases the font size by 5% (* 0.95) each step until the texts fits inside the box. You can change the multiplier to achieve a more precise result or to increase performance.