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

CSV and Script to Transform Text to Fit?

Community Beginner ,
May 13, 2019 May 13, 2019

Hi everyone, I need to output about 2400 nametags with text formatting...

This is my first time doing something like this, so I started researching and found that I can use a CSV file to generate the name tags.

However, I also need the longer names to fit - I've been transforming each of these by hand to fit a couple of guides, but is there a way to script this?

It would save me WEEKS of work.

Thanks!!!

TOPICS
Actions and scripting
687
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
Adobe
Community Expert ,
May 13, 2019 May 13, 2019

You can have your script run and make a text layer, whatever size, then use resize to scale it to fit a certain width. This works best without word wrap and paragraph text block.

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 ,
May 14, 2019 May 14, 2019

Thanks Chuck. I wouldn't know how to do this, but also I would need to leave any text that already fits in the area to remain the same. For example, shorter names like "AJ" or "TOM" shouldn't stretch the full width to the guides.

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 ,
May 14, 2019 May 14, 2019

Keeping the shorter names is simple a matter of getting the size of the text box then sizing it only if it exceeds your allotted space. I did this with a script that I used for work - tens of thousands of images.

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 ,
May 14, 2019 May 14, 2019

Here's an example: the yellow box is a reference layer for the size that you want the text to fit. Both names were run through the script, by selecing each of those layers separately, and running the script. Only the layer named "Stephen" was resized (top one, bottom was was before the script was run).

#target photoshop

var doc = activeDocument;

var padding = 44

var curLayer = doc.activeLayer;

var refLayer = doc.layers.getByName('ref');

var leftSide = refLayer.bounds[0];

var rightSide = refLayer.bounds[2];

var size = rightSide-leftSide-padding;

var textLayerSize = curLayer.bounds[2]-curLayer.bounds[0];

if(textLayerSize>size){

    var scaleAmt = (size/textLayerSize)*100

    curLayer.resize(scaleAmt,scaleAmt)

    curLayer.translate(refLayer.bounds[0]-curLayer.bounds[0]+(padding/2),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
Community Beginner ,
May 14, 2019 May 14, 2019

Thanks Chuck, however my needs are a bit more detailed and differ a bit from this solution. I need to transform the text, not scale it. I also need to organize the document with a particular layer structure. Perhaps this is too complicated to describe via the forum... can I share my Photoshop file with you? perhaps the CSV as well?

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 ,
May 14, 2019 May 14, 2019
LATEST

The script I posted was just an example. I can understand not wanting to scale text, as it messes it up. You can calculate the font size with this script. I made it fit the size of the box, this time, no padding.

You can send my your stuff, but not sure if I have the time to do something other than just a simple script. PM me for my email.

#target photoshop

var doc = activeDocument;

var curLayer = doc.activeLayer;

var refLayer = doc.layers.getByName('ref');

var leftSide = refLayer.bounds[0];

var rightSide = refLayer.bounds[2];

var size = rightSide-leftSide;

var textLayerSize = curLayer.bounds[2]-curLayer.bounds[0];

if(textLayerSize>size){

    var scaleAmt = (size/textLayerSize)

    var dupe = curLayer.duplicate()

    dupe.textItem.size = dupe.textItem.size *scaleAmt

    dupe.name = 'test'

    }

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