Showing posts with label add text layer. Show all posts
Showing posts with label add text layer. Show all posts

Friday, June 3, 2011

Add image layer in photoshop with javascript

















Create Image Layer
I have just developed the code to add image as a layer in photoshop with the help of javascript

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







var fileRef = new File(app.path.toString() + "/Samples/test.jpg"); // 'samples' is a folder resides in Program Files\Adobe\Adobe Photoshop CS5\samples

//open (fileRef);

var doc = open(fileRef);

// get document name (and remove file extension)

var name = tempName[0];

// convert to RGB; convert to 8-bpc; merge visible

doc.changeMode(ChangeMode.RGB);

doc.bitsPerChannel = BitsPerChannelType.EIGHT;

doc.artLayers.add();

doc.mergeVisibleLayers();

// rename layer; duplicate to new document

var layer = doc.activeLayer;

layer.name = tempName[0];

layer.duplicate(newDoc, ElementPlacement.PLACEATBEGINNING);

// close imported document

doc.close(SaveOptions.DONOTSAVECHANGES);

Just go and try it.

Enjoy


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