Skip to main content
Participant
February 8, 2010
Answered

Layer Comps to JPG Save for Web

  • February 8, 2010
  • 2 replies
  • 10282 views

Hello everyone,

I'm using the "Layer comp to files" script a lot to send some designs to clients. And sometimes I need to send a lot of JPGs at once, wich are created with "Layer comps to files", but they are all around 300k or more, and when I use Safe for web it reduces the file size a lot! But I don't want todo it all manually again offcourse.

So I was wondering, is there any script what saves your Layer Comps JPGs to a JPG what is compressed with the Save for Web technology?

Thanks in advance.

Jeroen

This topic has been closed for replies.
Correct answer Michael_L_Hale

Find these lines in the script

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;

Replace with this

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;

And that should do it. Or you could adjust so it uses scriptlistner for the SFW like the script does for PNG. If you want the jpeg to keep some metadata you will need to use scriptlistner anyway as the DOM version doesn't allow metadata in export.

2 replies

Participant
November 16, 2017

I have tried modifying this script for PS CC 2015.5 and do not see any differences in the functionality of the stock script. I noticed that the 2015.5 version of the script includes "fileExtension = "jpg";" as shown below:

          case jpegIndex:

           fileExtension = "jpg";

             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;

Michael_L_HaleCorrect answer
Inspiring
February 8, 2010

Find these lines in the script

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;

Replace with this

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;

And that should do it. Or you could adjust so it uses scriptlistner for the SFW like the script does for PNG. If you want the jpeg to keep some metadata you will need to use scriptlistner anyway as the DOM version doesn't allow metadata in export.

Participant
February 9, 2010

Hi Michael,

Thanks for taking the time to answer my question. Really appreciated and I think we're almost getting there, but I'll get an error when I replace the lines with your script.

The error:

Error 23: does not have a value.
Line: 697
-> exportOpts.quality = Math.round( exportInfo.jpegQuality / 12 * 100 ) ); // exportInfo.jpegQuality is 0 to 12, SFW uses 0 to 100. this converts


I hope this helps and you can help me further.

Thanks in advance.

Greetings Jeroen

Inspiring
February 9, 2010

Sorry, typo in the code. Remove the extra ) in that line.