Skip to main content
Inspiring
September 16, 2010
Answered

Script debug - what's wrong with this picture?

  • September 16, 2010
  • 2 replies
  • 1871 views

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.

This topic has been closed for replies.
Correct answer Muppet_Mark-QAl63s

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?


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 ); }

2 replies

GhoulfoolAuthor
Inspiring
September 16, 2010

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.

Muppet_Mark-QAl63s
Inspiring
September 16, 2010

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…

GhoulfoolAuthor
Inspiring
September 16, 2010

Bug report filled out and away!

Oh and the link for the feature request/ bug report is here

Muppet_Mark-QAl63s
Inspiring
September 16, 2010

My first 'guess' would be that the layer has FX applied…?

GhoulfoolAuthor
Inspiring
September 16, 2010

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?

Muppet_Mark-QAl63s
Inspiring
September 16, 2010

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/