simple script - maybe can be batched

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

jarr_d

simple script - maybe can be batched

Post by jarr_d »

Good Day and thanks for the help,

Basically, I need to take a layer & nudge it up one pixel
save this as 001.png
then rinse & repeat,

nudging by one pixel and incrementing the filename until it reaches 100.

Much thanks if you can help,

jarr_d
Patrick

simple script - maybe can be batched

Post by Patrick »

Code: Select all// reference the open document
var docRef = app.activeDocument;
var layRef = docRef.activeLayer;

// start the counter at 1
var i = 1;

while (i <= 100) {
   // nudge up one pixel
   layRef.translate(0,-1);

   // add padding zeros to the file names
   if (i < 10) {
      var fname = "00" + i;
   };

   if (( i < 100) && (i > 9) ) {
      var fname = "0" + i;
   };

   if (i > 99) {
      var fname = i;
   };

   // save png file
   pngSaveFile = new File("/c/" + fname + ".png");
   docRef.saveAs (pngSaveFile , PNGSaveOptions, true, Extension.LOWERCASE);
   
   // increment counter
   i++;
};

One thing to note is this will only work properly if the image you are working with is 72dpi. The translate() function assumes this, if you work with a different resolution let me know and I can alter the code. Hope this helps,

Patrick
Mike Hale

simple script - maybe can be batched

Post by Mike Hale »

You can replace the block of if statements to pad the number with the function below

Code: Select allfunction zeroPad(num,pad) {
     var z = Math.pow(10,Number(pad))
     return num < z ? (Number( num) + z).toString().substr(1): num
}


To call the function in the loop use

Code: Select allzeroPad( i, 3 );
xbytor

simple script - maybe can be batched

Post by xbytor »

Or:

Code: Select allfunction zeroPad(n, s) {
   n = n.toString();
   while (n.length < s)  n = '0' + n;
   return n;
};
jarr_d

simple script - maybe can be batched

Post by jarr_d »

wow guys - thanks so much

This is for a samurize config i'm working on - it was such a pain doing it manually (kept forgetting which number I was at & if i had already nudged it & whatnot...


again - HUGE, HUGE, HUGE thanks!!!!

now to figure out how to work it

saved it as
C:\Program Files\Adobe\Adobe Photoshop CS2\Presets\Scripts\onepixel.jsx

ran, and it worked !

Again, much much much thanks

I posted on the samurize forums about it here:
http://www.samurize.com/modules/ipboard ... entry87977 ... entry87977