Script is Great - PNG Size is Gigantic!!!
Hi All,
I found this script that will save to PNG without having to go through all the step. It is from here - https://www.reddit.com/r/gamemaker/comments/346v82/photoshop_script_for_you_save_as_png/
It works perfectly.
The only issue is that the PNG file it saves is 50+MB!!! When I export PNGs they are usually about 150KB!
What in the code do I need to change? Thanks!
c.pfaffenbichler JJMack any ideas?
Here it is (sorry, don't know how to paste this in nicely):
// 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 originalDoc = app.activeDocument
// Check there is at least 1 visible layer.
var foundVisible = false
for (i = 0; i < originalDoc.layers.length; i++)
{
if (originalDoc.layers.visible)
{
foundVisible = true
break
}
}
if (!foundVisible){
alert("No visible layers found. PNG export failed.")
return
}
// Duplicate. We'll save the duplicate as a .png and close it.
var newDoc = originalDoc.duplicate()
// Photoshop must have a visible layer selected to merge visible layers, so we ensure there is one selected.
var dummyVisibleLayer = newDoc.artLayers.add();
newDoc.activeLayer = dummyVisibleLayer
// Merge the layers.
newDoc.mergeVisibleLayers()
// Remove all empty layers.
for (i = newDoc.layers.length-1; i >=0; i--)
{
if (!newDoc.layers.visible)
{
newDoc.layers.remove()
}
}
// Set up PNG save options.
pngOptions = new PNGSaveOptions()
pngOptions.compression = 0
pngOptions.interlaced = false
// Set up destination path.
savePath = File(originalDoc.path + "/" + originalDoc.name.replace(/\.[^\.]+$/, '.png'));
// Save!
newDoc.saveAs(savePath, pngOptions, false, Extension.LOWERCASE)
// Close the duplicate.
newDoc.close()
// Just in case, make sure the active document is the orignal one.
app.activeDocument=originalDoc
}
ExportPNG()
