Skip to main content
Inspiring
February 9, 2024
Question

Get image dimensions as float?

  • February 9, 2024
  • 2 replies
  • 386 views

This is a bit backward: 

var imageHeight = app.activeDocument.height.value;
if (imageHeight == 224)
{
  // do stuff
}

Didn't work for once - I assumed that image dimensions were ints, but there we go... 

Casting it to an int worked: 

if (parseInt(imageHeight) == 224)
{
  // do stuff
}

 

Case closed.

 

But! Just out on curiousity, how do you get the float value of  app.activeDocument.height??? - it always seems to report it as in int. Assuming that's what's going wrong.

I tried casting it as float and multiplying it by 1,000,000.

This topic has been closed for replies.

2 replies

Stephen Marsh
Community Expert
Community Expert
February 9, 2024

@Ghoul Fool this is a curious situation!

 

Did you explicitly set pixels as the unit of measure earlier in the script? Or was it just naturally assumed from the current ruler state?

 

EDIT: I just tested and even explicitly setting the units to px in the script still returns false.

 

alert(imageHeight.toSource()); even reports that the value is a number!
 
So annoying!

 

Inspiring
February 10, 2024

I'm glad you find it curious too!

There's no explicit unit set up in the script - as I use pixels  so assume that's been set and not changed.

Secondly, the images size is an odd 200 dpi,  256 x 224 pixels (w & h)

Thirrdly resizing the image to 72 dpi,  256 x 224 pixels (w & h) - the script works fine.

Legend
February 9, 2024
The "value" depends on the "height" object type, which is the same as the ruler units.
 
 
 
Inspiring
February 9, 2024

Units are pixels. Even without the "value" I get an object that's "244 px" and yet alert( app.activeDocument.height.value == 224) is false.

Legend
February 9, 2024
Yes, sometimes there is such a glitch. Using this method helps.
 
alert( Number(app.activeDocument.height.value) == 224)