Copy link to clipboard
Copied
How to check the raster image resolution in illustrator through script?
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);
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Thanks for the reply.
I hope this could be sovled in CS7?
regards,
Vinoth
Copy link to clipboard
Copied
Put in a feature request.
https://www.adobe.com/cfusion/mmform/index.cfm?name=wishform
Copy link to clipboard
Copied
since you've ask a number of times I figure is kind of important for you. You've noticed you didn't get an answer, there's no navtive Resolution property in Illustrator....but there's hope, one way I think you can accoplish that is by using BridgeTalk to open the Illustrator file in photoshop....PS can easily get you the resolution and send it back to Illustrator.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
If this is as crucially important as the OP appears to think, taking the low road may help. Export to EPS and you got yourself an easily readable ASCII formatted text file that you can inspect at will.
By the way, as with all image formats that allow embedding one or *more* images into a single file, you cannot say anything about *every* embedded raster file at once -- you have to inspect each of them.
Copy link to clipboard
Copied
Hi Mark, I opened the Ai file manually in PS and I got the "Import PDF" dialog where I chose "images". That brings the chosen image at its native resolution...
...then I tried with VBA (very easy to get AI and PS to talk to each other) and it worked as expected...
let me try with BridgeTalk...hope there's no issues.
Copy link to clipboard
Copied
ok, here's the BridgeTalk version, it works with Linked or Embedded images...it was a good exercise, but I think Molouapple's version is more straightforward
var idoc = app.activeDocument;
var idocname = idoc.fullName;
//alert(idocname);
//$.writeln(idocname);
var bt = new BridgeTalk;
bt.target = "photoshop";
var msg = "\n" +
"var pdfOpts = new PDFOpenOptions;\n" +
"pdfOpts.page = 3;\n" +
"var file = new File('" +idocname+"');\n" +
"var idoc = app.open(file, pdfOpts);\n" +
"resolution = idoc.resolution;\n"
bt.body = msg;
bt.onResult = function(resObj) {
var res = resObj.body;
alert("Resolution = " + res);
}
bt.send();
Copy link to clipboard
Copied
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);
Copy link to clipboard
Copied
Great job, Moluapple. Will be quite handy in the future.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
If you want to use it on a file, you will have to use a loop which loops through the rasterImages in the file. Right now it requires the file to be open and a raster image selected.
Copy link to clipboard
Copied
Great. You saved lot of time.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
I know I'm late to the party here, and i wish i could be the dude who gives you an explanation for how and why this works..... but im completely baffled...
bumping this to the top to see if anyone else can shed some light.