I'm just getting the hang of Photoshop scripting, and have looked everywhere, but I can't find any way of changing a canvas size relative to the current canvas using scripting.
My current script is below..it sets a selection to the active layer and crops/ flattens the image. Now I want to add a ten pixel border relative to the size of the canvas. Does anyone have any idea how this would be accomplished? I really don't want to have to create an action just to run the canvas resize. Any help would be greatly appreciated!!
layerPixels2Selection = function(){
if(app.activeDocument.activeLayer.isBackgroundLayer){
return;// background doesn't have a transparency mask
}
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putProperty( charIDToTypeID( "Chnl" ), charIDToTypeID( "fsel" ) );
desc.putReference( charIDToTypeID( "null" ), ref );
var ref1 = new ActionReference();
ref1.putEnumerated( charIDToTypeID( "Chnl" ), charIDToTypeID( "Chnl" ), charIDToTypeID( "Trsp" ) );
desc.putReference( charIDToTypeID( "T " ), ref1 );
executeAction( charIDToTypeID( "setd" ), desc, DialogModes.NO );
}
//demo
layerPixels2Selection()
app.activeDocument.crop(app.activeDocument.selection.bounds);
app.activeDocument.mergeVisibleLayers()
You could try this:
// 2012, use it at your own risk;
#target photoshop
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
myDocument.resizeCanvas(myDocument.width + 20, myDocument.height + 20, AnchorPosition.MIDDLECENTER)
app.preferences.rulerUnits = originalRulerUnits;
};
North America
Europe, Middle East and Africa
Asia Pacific