Changing save options in Photoshop

Post Reply
aoswood
Member
Posts: 20
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: 1017
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
Member
Posts: 20
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.
Post Reply