Changing save options in Photoshop

Post Reply
aoswood
Newbie
Posts: 18
Joined: Wed Sep 14, 2011 6:16 pm

Changing save options in Photoshop

Post by aoswood »

I cannot get a file to save properly with PNG options in Photoshop CS6.

$outfile = new File($outfolder + '/' + $filename + ".png");
var pngSaveOptions = new PNGSaveOptions()
pngSaveOptions.compression=9 // (level of compression 0 .. 9 0 - without compression)
pngSaveOptions.interlaced=false
$doc.saveAs ($outfile, pngSaveOptions);

I get an extremely helpful error message from SWITCH:

"Script returned error: "
freddyp
Advanced member
Posts: 413
Joined: Thu Feb 09, 2012 3:53 pm

Re: Changing save options in Photoshop

Post by freddyp »

You should put a try .. catch to display errors. The main problem, however, is that you did not return the path to the created file. The correct code looks like this:

Code: Select all

var outfile = new File($outfolder + '/' + $filename + ".png");
var pngSaveOptions = new PNGSaveOptions();
pngSaveOptions.compression=9;    // (level of compression 0 .. 9 0 - without compression)
pngSaveOptions.interlaced=false;
try {
    $doc.saveAs (outfile, pngSaveOptions, true);
} catch (e) {
    $error = e;
}

//pass the output file back to Switch
$outfiles = new Array();
$outfiles.push(outfile.fsName);

Oh, and end your lines with a semi-colon.

Freddy
aoswood
Newbie
Posts: 18
Joined: Wed Sep 14, 2011 6:16 pm

Re: Changing save options in Photoshop

Post by aoswood »

I always forget those darn Semicolons. Thanks for you for the help worked perfectly. It also helped me out with another script that was broken.
nehavilash
Newbie
Posts: 7
Joined: Mon Nov 04, 2024 11:14 am
Location: India
Contact:

Re: Changing save options in Photoshop

Post by nehavilash »

This script works great for saving PNGs with specific options. If you're optimizing PNGs for web usage, you could also consider using an image compressor tool like this png compressor after saving the file to ensure minimal file size without quality loss.
Post Reply