0

This is a variation on a number of previous questions, but I seem to have a unique situation.

  • I have a photoshop file.
  • It has many layer groups, each forming a distinct and complete image to be exported
  • These images have been exported once already
  • The resultant image names are the same as the layer group names

So, I now have a folder with images correctly. For example:

One group layer might hypothetically be:

  • 2015-12-02-on-a-boat

This has been exported for web as:

  • 2015-12-02-on-a-boat.png

There are hundreds of layer groups, and this seems the most appropriate method of dealing with these similar but unique images.

As part of the move to responsive design, this process needs to now create resized images. For example the layer group:

  • 2015-12-02-on-a-boat

.. now needs to export in 4 separate sizes to

  • 2015-12-02-on-a-boat.png
  • 2015-12-02-on-a-boat-500.png
  • 2015-12-02-on-a-boat-1000.png
  • 2015-12-02-on-a-boat-1300.png

My question:

Is it possible to automate this process? Using a step through quasi programming process:

foreach (layer groups) {
 1. Enable visibility on a layer group
 2. Export for web, using the layer group name
 3. Export for web again, but also resize to 500px wide, appending "-500"
 4. Export for web again, but also resize to 1000px wide, appending "-1000"
 5. Export for web again, but also resize to 1300px wide, appending "-1300"
 6. Remove visibility on layer group
}

Even if I couldn't foreach, items 1-6 would save me a huge amount of time.

Having played around with photoshop actions I don't know how to access items such as layer name, which is the point of the whole exercise.

I'm actually a developer, so I'm not afraid of getting my hands dirty in some macros or code.. but I don't see how to do that. I don't even see how to get to the code itself.. if that's even accessible!

  • 1
    Is there no duplicate close enough in the 432 other questions about batch processing? – PieBie Dec 16 '15 at 20:26
  • Nope. I had a solid look. While there are "other ways", I specifically want to know the above question, not a variation on it... hence the question. Specifically - the "layer group" question has never been mentioned. – elb98rm Dec 16 '15 at 20:45
1

How can I easily assembly a sprite sheet? has a script sample which (in part) deals with iterating through layers and toggling visibility.

And How to automate exporting multiple PNGs with different sizes from Photoshop? has a link in "Justin Putney"'s answer which contains the following snippet that handles an array of sizes, defines a filename, and "save for web":

Here's the direct link to GitHub: https://gist.github.com/appsbynight/3681050 )

// Save icons in PNG using Save for Web.
var sfw = new ExportOptionsSaveForWeb();
sfw.format = SaveDocumentType.PNG;
sfw.PNG8 = false; // use PNG-24
sfw.transparency = true;
doc.info = null; // delete metadata
var icons = [
{"name": "iTunesArtwork@2x", "size":1024},
{"name": "iTunesArtwork", "size":512},
{"name": "Icon", "size":57},
{"name": "Icon@2x", "size":114},
{"name": "Icon-72", "size":72},
{"name": "Icon-72@2x", "size":144},
{"name": "Icon-Small", "size":29},
{"name": "Icon-Small@2x", "size":58},
{"name": "Icon-Small-50", "size":50},
{"name": "Icon-Small-50@2x", "size":100}
];
var icon;
for (i = 0; i < icons.length; i++)
{
icon = icons[i];
doc.resizeImage(icon.size, icon.size, // width, height
null, ResampleMethod.BICUBICSHARPER);
var destFileName = icon.name + ".png";
if ((icon.name == "iTunesArtwork@2x") || (icon.name == "iTunesArtwork"))
{
// iTunesArtwork files don't have an extension
destFileName = icon.name;
}
doc.exportDocument(new File(destFolder + "/" + destFileName), ExportType.SAVEFORWEB, sfw);
doc.activeHistoryState = startState; // undo resize
}

If all of the above is too much, I will note that a "save for web" recorded action will store the folder destination, but will use the current filename for the export when batching.

If you set up a set of temporary bins that match the hardcoded "save for web" folders recorded in an action: "resize, save-for-web, resize save-for-web, resize, save-for-web, [...], revert, close" and run the action on a whole folder of images, you will wind up with a collection of folders, one for each size.

You can then use OS batch files or any other programming/scripting to manipulate the filenames and move them to their final folder destination.

  • Adobe has scripting documentation. You can use javascript, VBscript or applescript. You can also search GD for "jsx photoshop" for a lot of other Q&A regarding scripting. – Yorik Dec 16 '15 at 21:42
  • These are a great couple of suggestions/resources. It's not a complete answer, but I'm upvoting for pushing in the right direction. – elb98rm Dec 17 '15 at 1:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.