• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
2

Get image dimensions as float?

Engaged ,
Feb 09, 2024 Feb 09, 2024

Copy link to clipboard

Copied

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.

Views

84

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Feb 09, 2024 Feb 09, 2024

Copy link to clipboard

Copied

The "value" depends on the "height" object type, which is the same as the ruler units.
 
 
 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 09, 2024 Feb 09, 2024

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Feb 09, 2024 Feb 09, 2024

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 09, 2024 Feb 09, 2024

Copy link to clipboard

Copied

@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!

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 10, 2024 Feb 10, 2024

Copy link to clipboard

Copied

LATEST

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)

image_size.jpg

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines