serializing PSD export

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

Mike Hale

serializing PSD export

Post by Mike Hale »

I am glad that you have it working but the script I posted does not use Number. It already uses parseInt.
cece

serializing PSD export

Post by cece »

Hi Mike,

it didn't work with "parseInt" it did when I chaged that to "numbers".

Thanks Again!
mltb

serializing PSD export

Post by mltb »

I have a similar issue as cece, but I am very unfamiliar with scripting. However, I am familiar with actions.

I have a PSD file (named "product_.psd) that has 6 layers, subsequently named 01, 02, ..., 06. I turn on only the first layer, then do a Save For Web. I need to save for web because the files need to upload very quickly. I rename the file "product_01.jpg." Then I turn off the first layer and turn on the second layer, do a Save For Web, and rename the file "product_02.jpg." I continue this process until I've gotten to the last layer with "product_06.jpg."

The "File > Scripts > Export Layers to Files" works great but I need the files to be much smaller in size as they are for the web. Thus, Save For Web.

How do I create an action with scripting that does all that: Save For Web, rename, hide layer, show layer, ... (repeat)? It's the renaming part that I don't know how to work. I tried to create an action, but at the Save For Web step, it wants to rewrite over the last saved file. Thank you! (Photoshop CS4)
Mike Hale

serializing PSD export

Post by Mike Hale »

If Export Layers to Files works for you except for SFW it would be easier to to edit the script so it saves jpgs using SFW. Open the script in a plain text editor, Extendscript Toolkit that ships with Photoshop a good choice. Then find 'case jpegIndex'. Comment out that case and replace it with SFW. The needed code is below.

Code: Select all        /*case jpegIndex:
           docRef.bitsPerChannel = BitsPerChannelType.EIGHT;
            var saveFile = new File(exportInfo.destination + "/" + fileNameBody + ".jpg");
            jpgSaveOptions = new JPEGSaveOptions();
            jpgSaveOptions.embedColorProfile = exportInfo.icc;
            jpgSaveOptions.quality = exportInfo.jpegQuality;
            docRef.saveAs(saveFile, jpgSaveOptions, true, Extension.LOWERCASE);
            break;*/
case jpegIndex:
     docRef.bitsPerChannel = BitsPerChannelType.EIGHT;
     var saveFile = new File(exportInfo.destination + "/" + fileNameBody + ".jpg");
     var exportOpts = new ExportOptionsSaveForWeb( );
     exportOpts.format = SaveDocumentType.JPEG
     exportOpts.includeProfile = exportInfo.icc;
     exportOpts.quality = Math.round( exportInfo.jpegQuality / 12 * 100 ); // exportInfo.jpegQuality is 0 to 12, SFW uses 0 to 100. this converts
     if ( saveFile.exists ) saveFile.remove( );// avoid file exists overwrite dialog
     docRef.exportDocument( saveFile, ExportType.SAVEFORWEB, exportOpts );
     break;
mltb

serializing PSD export

Post by mltb »

Mike, that's awesome!!! Thanks for your help. One last question:

Currently, when I run "Export Layers to Files," it numbers it with four digits, then adds the name of the layer (2-digit number). For example, the first file exported is "product_0000_00.jpg." Then the next file is "product_0001_01.jpg." I'd like it omit the 4-digit number in the middle and just take on the name of the layer. Thus, "product_01.jpg, product_02.jpg," etc.

Where in the script does it number the file name? I'd like to disable it, if that's possible. Thanks once again.
Mike Hale

serializing PSD export

Post by Mike Hale »

Code: Select all        var fileNameBody = fileNamePrefix;
        fileNameBody += "_" + zeroSuppress(i, 4);
        fileNameBody += "_" + layerName;
        fileNameBody = fileNameBody.replace(/[:\/\\*\?\"\<\>\|]/g, "_");  // '/\:*?"<>|' -> '_'
        if (fileNameBody.length > 120) {
         fileNameBody = fileNameBody.substring(0,120);
       }That is where the file name is set. If you don't want numbers just comment out the zeroSuppress line like thisCode: Select all// fileNameBody += "_" + zeroSuppress(i, 4);But remember that a document can have more than one layer with the same name. If that is the case without zeroSuppress or something similar some files may be overwritten. But it sounds like you will be ok, just keep that in mind if you run the modified script on a different type document.