CSV and Script to Transform Text to Fit?
Copy link to clipboard
Copied
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!!!
Explore related tutorials & articles
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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)
}
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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'
}

