Saturday, July 6, 2019

Script to move layer in photoshop


I'd like to have a script that moves one of two layer in a photoshop session by one pixel, save the output as a png and repeat. Here's my attempt (it complains that transform is not avaialable, but I'm using CS6):


// Save selected layer to variable:

app.preferences.rulerUnits = Units.PIXELS;

var docRef = activeDocument;
var layerRef = docRef.activeLayer;


for (var dy = 1; dy < 20 ; dy++) {

MoveLayerTo(layerRef,-1,0);

var opts;
opts = new ExportOptionsSaveForWeb();
opts.format = SaveDocumentType.PNG;
opts.PNG8 = false;
opts.quality = 100;

var suffix = zeroPad(dy,5)
var pngFile = new File("/path/to/file/"+suffix+"filename.png");

//Folder path for new images

docRef.exportDocument (pngFile, ExportType.SAVEFORWEB, opts);

}



function zeroPad(n, s) {
n = n.toString();
while (n.length < s) n = '0' + n;
return n;
};

//******************************************
// MOVE LAYER TO
// Author: Max Kielland
//

// Moves layer fLayer to the absolute
// position fX,fY. The unit of fX and fY are
// the same as the ruler setting.

function MoveLayerTo(fLayer,fX,fY) {

var Position = fLayer.bounds;
Position[0] = fX - Position[0];
Position[1] = fY - Position[1];


fLayer.translate(-Position[0],-Position[1]);
}


No comments:

Post a Comment

technique - How credible is wikipedia?

I understand that this question relates more to wikipedia than it does writing but... If I was going to use wikipedia for a source for a res...