Ahh creating product images for clients ecommerce sites – dontcha just love it?
Usually I insist that the client or the designer provide all product images in a uniform size with a suitable naming convention, but in my madness on this current project I said I would do the photo cropping/tweaking.
The client sends me a random set of product shots in a variety of sizes & orientations.
So in Photoshop I create a standard size PSD and drag and drop and move these motley collection of pictures around until I have a multi layer PSD with all the layers nicely named for the products they represent.
Surely there must be a “Save Layers as JPGS” option in Photoshop?
Alas no – so I had to learn how to script in Photoshop!
I found this very useful post here:
http://ask.metafilter.com/4903/Is-it-possible-to-batch-process-layers-in-Photoshop
On which I based my findings.
After installing the Scripts plugin (see previous article for link) I wrote the following javascript script to save off each layer as a separate JPG file.
try
{
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++){
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();
jpgFile = new File( docRef.path+"/"+docRef.activeLayer.name+".jpg" );
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = 1;
activeDocument.saveAs(jpgFile, jpgSaveOptions, true,
Extension.LOWERCASE);
saveFile = saveOptions = null;
docRef2.close(SaveOptions.DONOTSAVECHANGES);
counter++;
}
}
docRef.selection.deselect();
docRef = null
docRef2 = null
}
catch(someError)
{
alert( "JavaScript error occured. Message = " + someError );
}
I saved this as “01LayersToJPGs.js” in the Photoshop \ Presets \ Scripts subdirectory.
So now if I have my multi layer PSD open and run this script (File > Automate > Scripts) It will whirr away and save each image off as a separate jpg.
A nice unexpected touch is that it saves the image dead center within a blank white background – which certianly helped making some of the tiny images look better!
As usual I’d love your feedback on this!
(BTW I’m only using Photoshop 7 – there may well be a way of doing this automatically in later versions of Photoshop!)