Copy link to clipboard
Copied
I wrote a script a while back which shrinks and saves out images in png format. Nothing fancy. It works fine. I am happy. However yesterday, I discovered that it baulked at a certain file. Initally I thought it was a problem with the script (and that may be the case - i'm still new to scripting) but it worked with every other image I've thrown at it. Ergo it must be something wrong with the image.
Now here's the thing: I also noticed that adding a new layer underneath the existing single layer and then merging down allowed the script to work fine. So what is wrong with the inital image before it's had a new layer added and merged? Or what does adding and merging do to an image do to fix as I can't see any visual difference?
Here is the bare bones of the script:
// Set filePath and fileName to source path
filePath = "C:\\temp" + "/" + 'debugme' + '.png';
// save out the image
var pngFile = new File(filePath);
pngSaveOptions = new PNGSaveOptions();
pngSaveOptions.embedColorProfile = true;
pngSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
pngSaveOptions.matte = MatteType.NONE;
pngSaveOptions.quality = 1;
pngSaveOptions.PNG8 = false;
pngSaveOptions.transparency = true;
activeDocument.saveAs(pngFile, pngSaveOptions, false, Extension.LOWERCASE);
I would include the two psds (one that works and the one that doesn't) only this forum doesn''t seem to allow .psd files - and saving them out in another format is the whole problem.
A quick test and this resolved the issue for me…
#target photoshop filePath = '~/Desktop/Testing.png'; // save out the image var pngFile = new File(filePath); pngSaveOptions = new PNGSaveOptions(); pngSaveOptions.embedColorProfile = true; pngSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE; pngSaveOptions.matte = MatteType.NONE; pngSaveOptions.quality = 1; pngSaveOptions.PNG8 = false; pngSaveOptions.transparency = true; clearLayerStyle(); activeDocument.saveAs(pngFile, pngSaveOpti
...Copy link to clipboard
Copied
My first 'guess' would be that the layer has FX applied…?
Copy link to clipboard
Copied
It had an effect applied to it yes (at a previous point in it's life) but that was altered with create layers and then merging down.
Do you suspect that some effect legacy is still lingering on causing the file not to be saved properly?
Copy link to clipboard
Copied
Sorry that was my misunderstanding… I thought that adding a transparent layer below and merging down resolved your issue… If that was the case then I would have suspected a layer effect to be having an influence. Could you not put your sample psd files on a web file sharing host like: http://www.senduit.com/
Copy link to clipboard
Copied
I tried senduit but it or me are having technical difficulties, so I put them on
http://drop.io/eivj7ha
Copy link to clipboard
Copied
Well you have me stumped with that one and I think it could be a possible bug? There would appear to be NO layer styling to either of those documents… However if I navigate to Menubar/Layers/Layer Style in your document 'fileworks.psd' there is NO option to clear layer style on the other hand in file 'filefails.psd' there is an option to clear even though it appears to have none and if I do so the file saves just fine. I think you could use a scriptlistener bit of code to do this as a matter of course. But it does look like something is left over in file when you flatten the style?
Copy link to clipboard
Copied
A quick test and this resolved the issue for me…
#target photoshop filePath = '~/Desktop/Testing.png'; // save out the image var pngFile = new File(filePath); pngSaveOptions = new PNGSaveOptions(); pngSaveOptions.embedColorProfile = true; pngSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE; pngSaveOptions.matte = MatteType.NONE; pngSaveOptions.quality = 1; pngSaveOptions.PNG8 = false; pngSaveOptions.transparency = true; clearLayerStyle(); activeDocument.saveAs(pngFile, pngSaveOptions, false, Extension.LOWERCASE); function clearLayerStyle() { function cTID(s) { return app.charIDToTypeID(s); }; function sTID(s) { return app.stringIDToTypeID(s); }; var desc01 = new ActionDescriptor(); var ref01 = new ActionReference(); ref01.putEnumerated( cTID('Lyr '), cTID('Ordn'), cTID('Trgt') ); desc01.putReference( cTID('null'), ref01 ); executeAction( sTID('disableLayerStyle'), desc01, DialogModes.NO ); }
Copy link to clipboard
Copied
Wow, thanks Muppet Mark! I had a feeling it would be something obscure, like the layer styles not clearing properly or a residual bit of information that needed to be cleared.
Copy link to clipboard
Copied
IMO this would look like a bug having never found one I don't know where you would report it but I think you should…
Copy link to clipboard
Copied
Bug report filled out and away!
Oh and the link for the feature request/ bug report is here
Copy link to clipboard
Copied
Saves fine for me, it could be that your code isn't right? Please try this...
#target photoshop
sfwPNG24( '~/Desktop/Testing.png');
function sfwPNG24(saveFile){
var pngOpts = new ExportOptionsSaveForWeb;
pngOpts.format = SaveDocumentType.PNG
pngOpts.PNG8 = false;
pngOpts.transparency = true;
pngOpts.interlaced = false;
pngOpts.quality = 100;
activeDocument.exportDocument(new File(saveFile),ExportType.SAVEFORWEB,pngOpts);
}
Copy link to clipboard
Copied
Paul that works for me also. I'm not so sure it's a bug with the path construction (as it still failed with filePath = "~/Desktop/Testing.png")
What's the differerence beweeen save as a PNG and exportDocument for example?
Copy link to clipboard
Copied
PNGSaveOptions has only one option and thats interlaced (bool)
Unfortunatley you are using code that has been about for a long time and it's wrong.
Copy link to clipboard
Copied
This also works as on ordinary saveas..
#target photoshop
savePNG( '~/Desktop/Testing.png');
function savePNG(saveFile){
pngSaveOptions = new PNGSaveOptions();
activeDocument.saveAs(new File(saveFile), pngSaveOptions, true, Extension.LOWERCASE);
}
Copy link to clipboard
Copied
I'm not sure it is a bug. At least not a bug with the file or layer. The filefail.psd layer has 'Tranparency Shapes Layer' off in the advanced blending.
And as Paul points out the filefile.psd does save as png if the save path is correct. I think if there is a bug it has to do with how you are creating the save file path.
Copy link to clipboard
Copied
Mike, I ran saving both files to the same location at my desktop using the same code for each so I don't think it is a path issue. And yup I did trash the one that saved before running the second…
Not that it should matter… One saved fine the other kicked back a bouncy PS icon in the doc with a caution by layers in a save dialog box stating that saving to PNG would require save as copy… Paul is using SFW I did not try those options…
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more