Extendscript way to "preview" changes to a photoshop document?
I'm currently trying to make a photoshop panel that will let you preview different changes to a document, so that you can visually compare them to see which you like best. I've been able to create a basic CEP panel and achieve simple effects with Extendscript on my active document, and I can also save and load versions of the current document in my panel folder.
What I'm struggling with now is how to "duplicate" in memory the open document, apply a change to it, and then either display it or save it off to a different file. I don't want to alter the app.activeDocument.
For instance, say I have the following in my JSX:
var sanitizedFilePath = File(extensionPath + "/cache/lighter_shadows.jpg");
var exportOptions = new ExportOptionsSaveForWeb();
exportOptions.format = SaveDocumentType.JPEG;
app.activeDocument.artLayers[0].adjustColorBalance([80,80,80], [100,100,100],[100,100,100],false);
app.activeDocument.exportDocument(sanitizedFilePath, ExportType.SAVEFORWEB, exportOptions);
This will correctly lighten the image and save a copy of it to my temp folder, which I can then load, but it will of course change the currently open document as well. Instead, I'd like to do something like:
var lightShadows = new Document(app.activeDocument); //copy the active image to a new, undisplayed document
lightShadows.artLayers[0].adjustColorBalance([80,80,80], [100,100,100],[100,100,100],false); //apply some minor visual change
lightShadows.exportDocument(sanitizedFilePath, ExportType.SAVEFORWEB, exportOptions); //save it to a temp file
I believe using app.documents.add won't work, because it will always just create a newly opened empty document, whereas I don't want to "open" a new document in photoshop, I just want to work with one in code and then display it in my panel. I could perhaps make changes, export the file with those changes, then undo the changes, but it seems like it would be rather disruptive for a user.
Does anyone have any suggestions to help with this? Is there any good process for "previewing" changes to an image in a photoshop 2018 CEP panel?
Thank you for any advice! ![]()
