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: xbytor, DavideBarranca, Paul MR

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

Count text letters & set font size

Postby DhavalKatrodiya » Sun Apr 22, 2018 6:31 am

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

Postby wasfiwasfi » Tue May 01, 2018 8:18 pm

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

Postby wasfiwasfi » Tue May 01, 2018 8:19 pm

to make it count any other characters you need to add them to the :
var alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";


Return to “Help Me”

Who is online

Users browsing this forum: No registered users and 7 guests