Page 1 of 1

Count text letters & set font size

Posted: Sun Apr 22, 2018 6:31 am
by DhavalKatrodiya
hi, i am using photoshop variables to import csv file into photoshop.

the csv file contains three type of text lines.
1. 50 letter text line
2. 75 letter text line
3. 100 letter text line

i dont no anything about scripting. so i need help
i want a script that do following things.

for example, if text line contains "50 letters" set font size to "140 px".
if text line contains "75 letters" set font size to "110 px"
if text line contains "100 letters" set font size to "80 px"

Re: Count text letters & set font size

Posted: Tue May 01, 2018 8:18 pm
by wasfiwasfi
are you trying to make the text fit in one line by reducing the font size when text letters number is bigger !?
or they should have these specific font sizes for an other reason !?
does the text line will replace a text layer in a psd template or it will be added to a new document for each line ... ?
otherwise here is the code to count letters:

Code: Select all

function letterCounter(str) {
var letters = 0;
var alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
var ar = alphabet.split("");
for (var i=0; i<str.length;i++) {
if (ar.toString().indexOf(str[i]) > -1) {
letters = letters + 1;
}
}
return letters;
}


letters = letterCounter("Thank you");
alert(letters)

Re: Count text letters & set font size

Posted: Tue May 01, 2018 8:19 pm
by wasfiwasfi
to make it count any other characters you need to add them to the :
var alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

Re: Count text letters & set font size

Posted: Fri Jan 04, 2019 6:43 am
by habet222
thanks for help me