Is it possible to batch process layers in Photoshop?
January 26, 2004 6:20 AM   Subscribe

Is it possible to batch process layers in Photoshop? I need each layer as a separate JPG.
posted by niceness to Computers & Internet (3 answers total)
 
The latest version of Photoshop -- Photoshop CS -- will do this. The last couple of versions of Photoshop have been scriptable via Javascript (and a couple of other languages). CS comes with a script that exports each layer as a separate file.

Photoshop 7 is also scriptable, but it didn't come with this script. So I wrote it myself. If you have PS7, I should be able to find the script I wrote and send it to you.

My script didn't save JPEGs; it saved each layer as a PSD. But it's pretty easy to create an action that batch-converts all the PSDs to JPEGs. Actions don't require any programming skill. You just record yourself changing one PSD to a JPEG and then play back that recording on an entire folder full of JPEGs.
posted by grumblebee at 6:51 AM on January 26, 2004


Response by poster: Thanks very much Grumblebee, if it's not too much hassle that script would be much appreciated (mail on user page). I have a lot of layers to churn!
posted by niceness at 7:06 AM on January 26, 2004


You can download it here:

ftp://www.grumblebee.com/ps/layersToPsds.js

or you can recreate it yourself by copy/pasting the code from the end of this post (below).

If you've never run a script before, you'll have to first download and install the script plugin (free) from here:

MAC: http://www.adobe.com/support/downloads/detail.jsp?ftpID=1535
WIN: http://www.adobe.com/support/downloads/product.jsp?product=39&platform=Windows

Install the plugin. Then you'll have to place my script in the scripts folder (inside the Photoshop Presets folder).

Finally, inside Photoshop, select File > Automate > Script..., choose layersToPsd from the available scripts, and then press the Run button.

Note: this script only exposts VISIBLE layers. I decided this would be a good idea. That way, if you don't want a layer included, just turn it off. The files are saved in the same folder as the source file (the original layered document), so YOU MUST HAVE THAT FILE SAVED before running the script. The created files are all PSDs. If you want to use the script to export JPEGS, just run it as is -- then create an action saves PSDs to JPEGs (or some other file type of your choice) and batch apply it to the entire folder.

I have spent a small amount of time testing this, but it may have bugs. Let me know if you find any.

====

if (documents.length > 0)
{
displayDialogs = DialogModes.NO;
var docRef = activeDocument;
var filename = docRef.name;
var nameParts = filename.split(".psd");
var nameRoot = nameParts[0];
var counter = 0;
for (var i = 0; i < docref.layers.length; i++)br> {
if (docRef.artLayers[i].visible)
{
docRef.activeLayer = docRef.layers[i]
docRef.layers[i].copy();
var docRef2 = documents.add(docRef.width,docRef.height,docRef.resolution,docRef.activeLayer.name);
docRef2.paste();
docRef2.artLayers[1].remove();
var fullPath = docRef.path+"/"+nameRoot+counter+".psd";
saveFile = new File (fullPath);
saveOptions = new PhotoshopSaveOptions();
saveOptions.alphaChannels = true;
saveOptions.annotations = false;
saveOptions.embedColorProfile = true;
saveOptions.layers = true;
saveOptions.spotColors = true;
activeDocument.saveAs (saveFile, saveOptions, true, Extension.LOWERCASE);
saveFile = saveOptions = null;
docRef2.close(SaveOptions.DONOTSAVECHANGES);
counter++;
}
}
}
docRef.selection.deselect();
docRef = null
docRef2 = null
posted by grumblebee at 7:55 AM on January 26, 2004


« Older Can you help me find a sound recordist in Cuba?   |   I'm looking for web-based annotation software Newer »
This thread is closed to new comments.