Answered
Trying to do text to fit the width of the canvas dimensions
Hi,
The scipt below creates text layer puts a custom text and then it centers. I need the size of the text to fit the width of the canvas dimensions. Please, how can I do that?
Here is the script:
activeDocument.suspendHistory('CreateCenterTxt', 'CreateCenterTxt()');
function CreateCenterTxt() {
var doc = activeDocument;
var ArtLrs = doc.artLayers.add();
ArtLrs.kind = LayerKind.TEXT;
var TxtRef = ArtLrs.textItem;
TxtRef.contents = "Some Text";
TxtRef.size = 20; // Text must fit the width of the canvas
var docW = Number(doc.width);
var docH = Number(doc.height);
var layer = doc.activeLayer;
var bounds = layer.bounds;
var layerW = Number(bounds[2] - bounds[0]);
var layerH = Number(bounds[3] - bounds[1]);
var dX = (docW - layerW) / 2 - Number(bounds[0]);
var dY = (docH - layerH) / 2 - Number(bounds[1]);
layer.translate(dX, dY);
}Thanks,
Damian
