Skip to main content
johnt53984649
Inspiring
August 27, 2017
Answered

Photoshop Script for Saving Image

  • August 27, 2017
  • 1 reply
  • 6114 views

Suppose I want to create a photoshop script that will save the current document according to specifically-defined settings in the code itself.  How might I go about doing this?  For example, suppose I want this script to automatically save the current document as a .jpg file in such a way that my script can specify not only the file name, but also all of the parameters that would normally appear in the "JPEG Options" dialogue box.

-uS9S-53T6amyrRbhsU-Ig.png

I have no idea how I would access these properties within my script.  Would somebody please be able to provide some sample code that would save the current document as well as link to a resource that would explain how to modify these types of parameters via the script code?  Thank you.

This topic has been closed for replies.
Correct answer Chuck Uebele

Here's a snippet that has all the ways you can save a jpg. You can create a UI to set them or you can hard code them into your script. These all are not needed to specify, if you use the standard default options for saving jpgs.

var saveFolder = new Folder('/c/Save Folder/'); //enter path for where you want the file saved

var fileName = 'My File';

var doc= activeDocument

var jpgOptions = new JPEGSaveOptions();

jpgOptions.quality = 8; //enter number or create a variable to set quality

jpgOptions.embedColorProfile = true;

jpgOptions.formatOptions = FormatOptions.STANDARDBASELINE;

//other options///////////////////////////

//jpgOptions.formatOptions = FormatOptions.PROGRESSIVE;

//jpgOptions.formatOptions = FormatOptions.OPTIMIZEDBASELINE;

if(jpgOptions.formatOptions == FormatOptions.PROGRESSIVE){

    jpgOptions.scans = 3}; //only used with Progressive

jpgOptions.matte = MatteType.NONE;

//jpgOptions.matte = MatteType.BACKGROUND;

//jpgOptions.matte = MatteType.BLACK;

//jpgOptions.matte = MatteType.FOREGROUND;

//jpgOptions.matte = MatteType.NETSCAPE;

//jpgOptions.matte = MatteType.SEMIGRAY;

//jpgOptions.matte = MatteType.WHITE;

doc.saveAs (new File(saveFolder +'/' + fileName + '.jpg'), jpgOptions)

1 reply

Chuck Uebele
Community Expert
Chuck UebeleCommunity ExpertCorrect answer
Community Expert
August 27, 2017

Here's a snippet that has all the ways you can save a jpg. You can create a UI to set them or you can hard code them into your script. These all are not needed to specify, if you use the standard default options for saving jpgs.

var saveFolder = new Folder('/c/Save Folder/'); //enter path for where you want the file saved

var fileName = 'My File';

var doc= activeDocument

var jpgOptions = new JPEGSaveOptions();

jpgOptions.quality = 8; //enter number or create a variable to set quality

jpgOptions.embedColorProfile = true;

jpgOptions.formatOptions = FormatOptions.STANDARDBASELINE;

//other options///////////////////////////

//jpgOptions.formatOptions = FormatOptions.PROGRESSIVE;

//jpgOptions.formatOptions = FormatOptions.OPTIMIZEDBASELINE;

if(jpgOptions.formatOptions == FormatOptions.PROGRESSIVE){

    jpgOptions.scans = 3}; //only used with Progressive

jpgOptions.matte = MatteType.NONE;

//jpgOptions.matte = MatteType.BACKGROUND;

//jpgOptions.matte = MatteType.BLACK;

//jpgOptions.matte = MatteType.FOREGROUND;

//jpgOptions.matte = MatteType.NETSCAPE;

//jpgOptions.matte = MatteType.SEMIGRAY;

//jpgOptions.matte = MatteType.WHITE;

doc.saveAs (new File(saveFolder +'/' + fileName + '.jpg'), jpgOptions)

johnt53984649
Inspiring
August 27, 2017

Thanks, that gave me a really good start.  I appreciate it.