I'm making a batch script that is gonna take an original png image, save it to a image with RGB and an image with the alpha from the original image in the R channel.
Now, I've gotten almost all the way there, there's just one thing left. Saving the files.
Is there any way I can save as a specific filename, a specific filetype, and if possible change the number of bits in the PNG? (I only need the R channel in the alpha image).
var origDoc = open(file); var rgbExtension = "_rgb"; var alphaExtension = "_a"; var rgbPage = documents.add(origDoc.width, origDoc.height, 72.0, origDoc.name + rgbExtension,NewDocumentMode.RGB, DocumentFill.WHITE); CopyWithEmptyPixels(origDoc, rgbPage); var alphaPage = documents.add(origDoc.width, origDoc.height, 72.0, origDoc.name + alphaExtension,NewDocumentMode.RGB, DocumentFill.WHITE); CopyFillAlphaBlack(origDoc, alphaPage); rgbPage.save(); // Doesn't work, crashes the script. alphaPage.saveAs (origDoc.path + alphaExtension); // Also doesn't work, crashes the script. alphaPage.close(SaveOptions.SAVECHANGES); // Does work, but throws a popup. And I have around 400 files I need to do this on. Can't really afford to have popups.
save works on files that already have been saved to some volume previously, a newly created file lacks a path.
Ah, thank you. I hadn't found those examples and it works out now, cheers!
Don’t forget that saveAs will replace an existing of the same Path without prompting, so if you want to get a dialog for those cases you might have to include an if-clause and a confirm-dialog.