Friday, June 3, 2011

Text Layer add in Photoshop with Javascript















Add Text Layer
I have just developed the code to add text layer in photoshop with the help of javascript

It is quite easy to do so, here is the code to work with


var docRef = activeDocument;

// Now create a text layer at the front
var myLayerRef = docRef.artLayers.add();
//myLayerRef.rotate (180)
myLayerRef.kind = LayerKind.TEXT;
myLayerRef.name = "Filename";

var myTextRef = myLayerRef.textItem;

// strip the extension off
var fileNameNoExtension = docRef.name;
fileNameNoExtension = fileNameNoExtension.split( "." );
if ( fileNameNoExtension.length > 1 ) {
fileNameNoExtension.length--;
}
fileNameNoExtension = fileNameNoExtension.join(".");

myTextRef.contents = tempName[5];

// off set the text to be in the middle
myTextRef.position = new Array( docRef.width / 2, docRef.height / 2 );
myTextRef.size = Number(tempName[7]);
myTextRef.font=tempName[6];
//myTextRef.underline.UnderlineType.UNDERLINELEFT;
//set position of text LINE NO 221
myTextRef.justification = Justification.CENTER;
myTextRef.kind = TextType.PARAGRAPHTEXT;
myTextRef.width= docRef.width;
myTextRef.height= docRef.height/ 2;
myTextRef.position= [Number(tempName[1]), Number(tempName[2])];


////////////////////// CODE TO ADD TEXT IN LAYER ENDS /////////////////////////


Just go and try it.

Enjoy

No comments:

Post a Comment