Created
August 8, 2021 16:21
-
-
Save amadornes/32bff3b3ef53a97a487c4cce7551550b to your computer and use it in GitHub Desktop.
Photoshop PNG export script with no popups. Based on https://www.reddit.com/r/gamemaker/comments/346v82/photoshop_script_for_you_save_as_png/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Exports a saved multi-layered file as a .png in the same directory. | |
function exportPNG() { | |
// Confirm the document has already been saved and so has a path to use | |
try { | |
app.activeDocument.save(); | |
} catch(e) { | |
alert("Could not export PNG as the document is not saved.\nPlease save and try again.") | |
return | |
} | |
// Store the active doc handle in variable | |
var doc = app.activeDocument; | |
// Check there is at least 1 visible layer. | |
var foundVisible = false; | |
for (i = 0; i < doc.layers.length; i++) { | |
if (doc.layers[i].visible) { | |
foundVisible = true; | |
break; | |
} | |
} | |
if (!foundVisible) return; | |
// Set up PNG save options. | |
pngOptions = new PNGSaveOptions(); | |
pngOptions.compression = 9; | |
pngOptions.interlaced = false; | |
// Set up destination path. | |
savePath = File(doc.path + "/" + doc.name.replace(/\.[^\.]+$/, '.png')); | |
// Save! | |
doc.saveAs(savePath, pngOptions, true, Extension.LOWERCASE); | |
// Just in case, make sure the active document is the orignal one. | |
app.activeDocument=doc; | |
} | |
exportPNG(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment