Skip to main content
vinoth_mannu
Inspiring
July 2, 2012
Answered

Resolution check in illustrator

  • July 2, 2012
  • 3 replies
  • 17622 views

How to check the raster image resolution in illustrator through script?

This topic has been closed for replies.
Correct answer moluapple

This seems to solve it:

// select a rasterItem, no rotation or skew

72/app.selection[0].matrix.mValueA;

// also

72/app.selection[0].matrix.mValueD;

// for rotation applied(no skew) item

var item = app.selection[0],

    matrix = item.matrix,

    rotation = 180/Math.PI * Math.atan2(matrix.mValueC, matrix.mValueD);

item.rotate(rotation);

alert(72/item.matrix.mValueA);

item.rotate(-rotation);

3 replies

Stephen Marsh
Community Expert
Community Expert
March 18, 2019

As a scripting newb, the following is beyond me, however I would do something like:

Embedded image pixel width, divided by physical width of image on canvas in inches = width ppi value

Embedded image pixel height, divided by physical height of image on canvas in inches = height ppi value

Pick the smallest value of the two (they should be close), one may need to round the value to the closest integer

wckdtall
Inspiring
June 6, 2020

Illustrator makes this difficult, and not straight forward... plus percentage math isn't my forte. One can read the percentage of the image from the matrix mValueB and C, but if it's Linked the percentage is based on the resolution of the image. So as an example, we get:

 

LINKED: W: 1800px | W": 25in" and Link Panel reads W: 3300px | Scale: 113% | Resolution: 132dpi

EMBEDDED: W: 1800px | W": 25in" and Link Panel reads W: 3300px | Scale: 54.6% | Resolution 132dpi

 

The source image in photoshop reads 150dpi, but being that DPI is not readable in AI, the image must be embedded and at 0 rotation and then one can find the original image size and DPI by doing some math.

(Wpx / Scale) * 100 = Original Wpx
(Original Wpx / Current Wpx) * 72 = DPI of Image. 


wckdtall
Inspiring
June 6, 2020

Now I see the beauty of Moluapple's first block of code. If someone has a quick breakdown as to why DPI/Scale % = Resolution, I'd appreciate it. Also, There doesn't seem to be a clear explanation in docs on what the matrix is comprised of. A and D, seem to be the decimal form of scale %, and I'd assume TX and TY are Transformation? That leaves mValueB and mValueC.

moluappleCorrect answer
Inspiring
July 5, 2012

This seems to solve it:

// select a rasterItem, no rotation or skew

72/app.selection[0].matrix.mValueA;

// also

72/app.selection[0].matrix.mValueD;

// for rotation applied(no skew) item

var item = app.selection[0],

    matrix = item.matrix,

    rotation = 180/Math.PI * Math.atan2(matrix.mValueC, matrix.mValueD);

item.rotate(rotation);

alert(72/item.matrix.mValueA);

item.rotate(-rotation);

Larry G. Schneider
Community Expert
Community Expert
July 5, 2012

Great job, Moluapple. Will be quite handy in the future.

vinoth_mannu
Inspiring
July 6, 2012

Thanks for the script.

When we run this via illustrator saved files we get the alert of the document name only.

Could you please advice us how to proceed this script.

Larry G. Schneider
Community Expert
Community Expert
July 2, 2012

No matter how many time someone asks, that information is not available to scripting in AI. There is no rasterItem.resolution property to look at.

vinoth_mannu
Inspiring
July 3, 2012

Thanks for the reply.

I hope this could be sovled in CS7?

regards,

Vinoth

Larry G. Schneider
Community Expert
Community Expert
July 3, 2012