Photoshop CC 2018 JavaScript bug with some PNG files.

  • 1
  • Problem
  • Updated 9 months ago

Here are sample PNG (autogen.png) file and simple script (Photoshop2018PngBug.js).

Script tries to get document width and height (app.activeDocument.width) but these values are “NaN”. Then script makes workaround via select all and get current selection width and height - this is successful. After this it calls OuterGlow() function that was previously recorded by ScriptListener.8li - all values in Outer Glow effect are correct except Size which was set to 0, whereas it should be 6 (OuterGlowSettings.png).

So here are 2 problems:

  • “NaN” for doc width and height

  • Size in Outer Glow effect settings

This bug occurs with specific PNG files only and in Photoshop CC 2018 only (all versions including 19.1.0). In previous Photoshop versions (CC 2017 and earlier) - everything works fine. This particular PNG was saved in After Effects CC 2017. If we make some image modification (e.g. lines with brush) and just press Ctrl+S to save updated PNG, then reopen it in Photoshop - bug will still persist. The only workaround is to use “Save for Web” - after this updated PNG processed with this script without any issues.

https://www.dropbox.com/sh/qzn99kdfkwy06gp/AAAJOkYK0aVPmUfPookJ2myaa?dl=0
Photo of Andriy Astakhov

Andriy Astakhov

  • 8 Posts
  • 1 Reply Like

Posted 10 months ago

  • 1
Photo of Jaroslav Bereza

Jaroslav Bereza

  • 806 Posts
  • 187 Reply Likes
I can confirm that. Data are missing even in whole document Action Descriptor. This is bad.

var ref = new ActionReference();
        var idDcmn = charIDToTypeID( "Dcmn" );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idFrst = charIDToTypeID( "Trgt" );
        ref.putEnumerated( idDcmn, idOrdn, idFrst );
var desc = executeActionGet(ref);
Photo of Andriy Astakhov

Andriy Astakhov

  • 8 Posts
  • 1 Reply Like

Update:

I’ve added screenshot from TweakPNG (PngDpiInfo.png) where is Chunk “pHYs” with 0 dpi. If we remove this optional chunk - script will work fine. Also here is script workaround - paste this in the beginning:

if(doc.resolution == 0) { doc.resizeImage(undefined, undefined, 72, ResampleMethod.NONE); }

Photo of Jaroslav Bereza

Jaroslav Bereza

  • 800 Posts
  • 180 Reply Likes
Hmm you can't divide by zero indeed. That explains: "NaN" not a number
Photo of Andriy Astakhov

Andriy Astakhov

  • 8 Posts
  • 1 Reply Like
Yes, but Photoshop should handle this, as it did before (CC 2017 and earlier). In previous versions it just assign default resolution (72) in this case - just what I did in Update.
(Edited)
Photo of David Converse

David Converse

  • 438 Posts
  • 121 Reply Likes
Ok, this won't format correctly. :sigh: Try this instead to get dimensions.

this.run = dimTest();

function dimTest(){
    var doc = app.activeDocument;
    
    if(doc)
    {
        var width   = doc.width.value;
        var height  = doc.height.value;
    $.writeln(width);
    $.writeln(height);
    }
    }
(Edited)
Photo of Andriy Astakhov

Andriy Astakhov

  • 8 Posts
  • 1 Reply Like
It's NaN with your code either. And I don't see any differences with my code. I just keep the sample script simple without bloating it with unneeded stuff.
And yes, you can check it by yourself - all files are in dropbox.
Photo of David Converse

David Converse

  • 438 Posts
  • 121 Reply Likes
I downloaded your png file and tested it. The script returns 384, 384.

Above is just a snippet I wrote in the editor. The difference is getting the value property.

Put another way, you are doing it wrong.
Photo of Andriy Astakhov

Andriy Astakhov

  • 8 Posts
  • 1 Reply Like
It’s good that this script with this PNG works on your Photoshop, but it doesn’t work on mine. And as I’ve wrote before your code produce the same result - NaN - see screenshot - ConsoleNaN.png (in Dropbox).
And my code is correct - I do not see any differences with yours.
(Edited)
Photo of Eugen Govorun

Eugen Govorun

  • 1 Post
  • 0 Reply Likes
My similar case has been solved by parseInt() function:
w = parseInt(doc.width),
h = parseInt(docd.height);
(Edited)