Skip to main content
Participating Frequently
January 18, 2011
Question

Height and width of graphic in pixels

  • January 18, 2011
  • 2 replies
  • 2111 views

I am trying to get the height and width of a graphic in pixels. However, when I set the horizontal/vertical measurement units to pixels, I still get decimals for the geometricBounds coordinates (2.3, 500.2345234). Why is that? I would expect to get whole numbers.

This topic has been closed for replies.

2 replies

Kasyan Servetsky
Legend
January 23, 2011

You can get this info from link's metadata:

var myDoc = app.activeDocument;
var myLink = myDoc.allGraphics[0].itemLink;
var myLinkXmp = myLink.linkXmp;
var myLinkWidth = myLinkXmp.getProperty("http://ns.adobe.com/tiff/1.0/", "tiff:ImageWidth");
var myLinkLength = myLinkXmp.getProperty("http://ns.adobe.com/tiff/1.0/", "tiff:ImageLength");
alert("Pixel dimentions of the first link:\nWidth: " + myLinkWidth + " pixels\nHeight: " + myLinkLength + " pixels");

However, not all links contain it.

Harbs.
Legend
January 18, 2011

Why do you expect to get whole numbers?

InDesign does not snap to pixels...

Harbs

Participating Frequently
January 18, 2011

Then that's what I need to know. Still seems a little strange to me (I am not a designer, but a programmer). How are half pixels represented when displayed on screen?

Inspiring
January 18, 2011

Despite Adobe's efforts to convince the world of the contrary, "pixels" are not really an existing measurement unit. The "pixel" unit you are seeing is just InDesign that replaces "pt" with "px" in all dialogs.

Experiment #1: place an image of known pixel dimensions; for example, 128 x 64 pixels. Scale the screen to 100%. Is this image you see now 128 x 64 pixels? Measure by making a screen shot and opening it in Photoshop. (I grant you it's possible, but somehow I doubt it. InDesign does not know your screen size in pixels.)

Experiment #2: place an image of known pixel dimensions; for example, the same image as above. Now scale it horizontally and vertically by 99%. What size is this image, in pixels? Pick one:

(a) it's 128 x 64 pixels, because scaling has no effect on actual pixel content; only its effective resolution changed.

(b) it's 126.72 x 63.36 pixels, because that's what 99% of the dimensions calculate to.

(c) it's 127 x 63 pixels, because that's what it scales to, and your screen cannot display fractional pixels.

- - - -

All of this isn't really helping, isn't it. Try this: take your image dimensions in inches and multiply by the effective ppi of the image. That will give you a number of pixels.