Skip to main content
vinoth_mannu
Inspiring
Jul 2, 2012 10:07 AM UTC
Answered

Resolution check in illustrator

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

This topic is closed to new replies. Start a new post to keep the conversation going.
moluappleCorrect answer
Inspiring
Jul 5, 2012 3:53 AM UTC

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);

17 replies

Stephen Marsh
Community Expert
Community Expert
Mar 18, 2019 1:11 PM UTC

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

Translate
wckdtall
Inspiring
Jun 6, 2020 8:46 AM UTC

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. 


Translate
wckdtall
Inspiring
Jun 6, 2020 7:40 PM UTC

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.

Translate
moluappleCorrect answer
Inspiring
Jul 5, 2012 3:53 AM UTC

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);

Translate
Larry G. Schneider
Community Expert
Community Expert
Jul 5, 2012 4:39 PM UTC

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

Translate
vinoth_mannu
Inspiring
Jul 6, 2012 9:13 AM UTC

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.

Translate
Larry G. Schneider
Community Expert
Community Expert
Jul 2, 2012 5:32 PM UTC

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.

Translate
vinoth_mannu
Inspiring
Jul 3, 2012 10:35 AM UTC

Thanks for the reply.

I hope this could be sovled in CS7?

regards,

Vinoth

Translate
Larry G. Schneider
Community Expert
Community Expert
Jul 3, 2012 4:07 PM UTC