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: "
Changing save options in Photoshop
Re: Changing save options in Photoshop
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:
Oh, and end your lines with a semi-colon.
Freddy
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
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.
-
- Newbie
- Posts: 7
- Joined: Mon Nov 04, 2024 11:14 am
- Location: India
- Contact:
Re: Changing save options in Photoshop
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.