Count text letters & set font size

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

DhavalKatrodiya
Posts: 2
Joined: Sun Apr 22, 2018 6:09 am

Count text letters & set font size

Post 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"
wasfiwasfi
Posts: 45
Joined: Fri Nov 04, 2016 8:29 am

Re: Count text letters & set font size

Post 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)
wasfiwasfi
Posts: 45
Joined: Fri Nov 04, 2016 8:29 am

Re: Count text letters & set font size

Post by wasfiwasfi »

to make it count any other characters you need to add them to the :
var alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
habet222
Posts: 1
Joined: Fri Jan 04, 2019 6:41 am

Re: Count text letters & set font size

Post by habet222 »

thanks for help me