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


No comments:

Post a Comment