Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doersino/21bb660f47b1640ebe8e889777a636bc to your computer and use it in GitHub Desktop.
Save doersino/21bb660f47b1640ebe8e889777a636bc to your computer and use it in GitHub Desktop.
A Photoshop script that will repeatedly (re)apply the most recently used filter to the current document and save each iteration as a PNG image.
// A Photoshop script that will repeatedly (re)apply the most recently used
// filter to the current document and save each iteration as a PNG image.
//
// Usage:
// 1. Create an empty image, do some stuff to it, save it as a PSD somewhere
// (this is also where the results will end up).
// 2. Make sure there's only one layer. I think if there's more than one, the
// filter will be repeatedly applied to the selected layer only, and the rest
// should work as expected, but I didn't bother testing it.
// 3. Apply your desired filter with the desired settings (say, "Wave" with low
// amplitude range) once, then immediately undo.
// 4. Set the "iterations" variable below.
// 5. Run this script. I didn't bother adding any kind of progress output, so
// sit tight. (You can gauge it by the number of written files, though.)
// 6. If you want to compile the result images into a video, ffmpeg is your
// friend. Run something like the following:
// ffmpeg -framerate 24 -pattern_type glob -i '*.png' -pix_fmt yuv420p x.mp4
//
// Note that any existing files like "NNN.png" will be overwritten without
// asking. Also, Photoshop occasionally seems to occasinally pop up the filter
// dialogue again, no idea why. Just confirm.
//
// Only tested in Photoshop CS6.
//
// Partially based on:
// https://graphicdesign.stackexchange.com/a/16920
// https://stackoverflow.com/q/62484215
//
// Canonical location:
// https://gist.github.com/doersino/21bb660f47b1640ebe8e889777a636bc
//
// Video whose creation this script was written to facilitate:
// https://www.youtube.com/watch?v=4aIerApduy4
#target photoshop
app.bringToFront();
var iterations = 1000;
function repeatLastFilter() {
runMenuItem(app.charIDToTypeID("LstF"), true);
}
var n = 1;
function generateIncrementingFilename() {
var padLength = 4;
var filename = "filtered-1" + (new Array(padLength + 1 - n.toString().length)).join('0') + n;
n++;
return filename;
}
var basePath = app.activeDocument.path;
function saveCurrentLayerAsPNG() {
var saveFileHandle = File(basePath + "/" + generateIncrementingFilename() + ".png");
var pngSaveOptions = new PNGSaveOptions();
activeDocument.saveAs(saveFileHandle, pngSaveOptions, true, Extension.LOWERCASE);
}
function main() {
for (var i = 0; i < iterations; i++) {
saveCurrentLayerAsPNG();
repeatLastFilter();
}
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment