Page 1 of 1
Changing save options in Photoshop
Posted: Mon Feb 23, 2015 10:34 am
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: "
Re: Changing save options in Photoshop
Posted: Mon Feb 23, 2015 10:35 am
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
Re: Changing save options in Photoshop
Posted: Mon Feb 23, 2015 10:35 am
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.
Re: Changing save options in Photoshop
Posted: Wed Jan 08, 2025 10:24 am
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.