I got the problem when trying to get width and height of active document. And change Unit to Pixel doesn't work
I just open 1 png image into photoshop then run the script. Alert width and height and got "NaN px"
Here is my simple code:
var startRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
try{
var doc = app.activeDocument;
var currentWidth = doc.width;
var currentHeight = doc.height;
alert(currentWidth);
alert(currentHeight);
}catch(e){
alert(e);
}
app.preferences.rulerUnits = startRulerUnits;
I tried this script with 2 png image file: "spark_1" and "spark_1_resize"
- "spark_1": 1024x1024 px => script showing "NaN px" with it
- "spark_1_resize": 512x512 px => script works and showing "512px"
I have no idea why is that
I really appreciate with any help ❤
Thank you
"NaN px" Return When Get Document Size
-
- Posts: 3
- Joined: Sun Jun 12, 2022 11:29 am
"NaN px" Return When Get Document Size
- Attachments
-
- spark_1_resize.png (17.13 KiB) Viewed 1255 times
-
- spark_1.png (40.76 KiB) Viewed 1255 times
Re: "NaN px" Return When Get Document Size
Compress spark_1.png and attach to your next post, so I can run myself your script on that file.
-
- Posts: 3
- Joined: Sun Jun 12, 2022 11:29 am
Re: "NaN px" Return When Get Document Size
Sorry , here is the image
- Attachments
-
- spark_1.rar
- (36.71 KiB) Downloaded 103 times
Re: "NaN px" Return When Get Document Size
I'm twice alerted by 1024 px, so I guess something changed in file when transfering, or it's something different on your side.
Maybe try on the file you uploaded to your post? I have Photoshop CS6 and CC 2022, what is yours?
The only difference is in CS6 the resolution is 72, while in CC 2022 it's 1.
Maybe try on the file you uploaded to your post? I have Photoshop CS6 and CC 2022, what is yours?
The only difference is in CS6 the resolution is 72, while in CC 2022 it's 1.
-
- Posts: 3
- Joined: Sun Jun 12, 2022 11:29 am
Re: "NaN px" Return When Get Document Size
Hi, i just found a solution
These images had problem with resolution. I changed resolution from 1 to 72 Pixels/Inch
Scripts works!
Thank you ❤
These images had problem with resolution. I changed resolution from 1 to 72 Pixels/Inch
Scripts works!
Thank you ❤
Re: "NaN px" Return When Get Document Size
As I say the script alerted numeric values on my side, so I wonder what exact Ps version you use that you couldn't have same result?