Copy link to clipboard
Copied
Hello,
I have simple problem - I need to extract the PPI (resolution) of each raster item within the AI document. For now I've managed to calculate approximate values using this formula ->
var widthInPixels = Math.abs(72 / item.matrix.mValueA);
var heightInPixels = Math.abs(72 / item.matrix.mValueD);
Where:
item - is the raster item, no matter the type object (it can be raster item, placed item, etc); every such object has matrix property which values (mValueA, mValueD -> scaling percentage width, scaling percentage height) refer to the scaling factor in percentage of the object itself. For example if we have AI document with embedded PNG file with original dimensions 3000x3000 and we scale the image within the document to 4000x4000 then the mValueA and mValueD will have value of 1.33333 and -1.33333 respectively or with other words said we have sized up the image with 33%. Initially when the image is placed within the document it is scaled to 100% (meaning that is has not been resized). When we downsize the image the percentage of scaling drops down and vice versa. Example: if we scale the placed image to 1500x1500 the scaling percentage will be down with 50%, having mValueA and mValueD to have value of 0.5 and -0.5 respectively.
We can think of the initial 100% value like a boundary - if a value exceeds it - it means the object has been sized up and otherwise down sized.
My question is - is this the right formula for calculating the PPI? I have extremly odd case - in the document file there are two linked JPG (or Joint Photographic Experts Group) images. The output of the same formula for the first image is correct, but for the second image the value is twice smaller than the actual.
The real value for PPI is 250x433.
With the formula the output value is 125x217.
What the *** I am doing wrong?
1 Correct answer
Your script is giving different answers for the placed files most likely because they have different resolutions (ppi). Not every placed file has a resolution of 72 ppi, but that is the number you are using in your calculation.
 
If you look at the screenshot below, you can see two almost identical images. The only difference is one is saved at 150 ppi and the other at 72 ppi. Both were only placed and not scaled. If you look carefully, they are the exact same pixel and file size but they have dif
...Explore related tutorials & articles
Copy link to clipboard
Copied
Your script is giving different answers for the placed files most likely because they have different resolutions (ppi). Not every placed file has a resolution of 72 ppi, but that is the number you are using in your calculation.
 
If you look at the screenshot below, you can see two almost identical images. The only difference is one is saved at 150 ppi and the other at 72 ppi. Both were only placed and not scaled. If you look carefully, they are the exact same pixel and file size but they have different physical sizes (dimensions in Ai). This is because of their set ppi.
 
Now, If I scale both placed images down by 50% your calculation would yield 72 / .5 = 144 for both images. And as you can see from the Document Info palette below that isn't correct.
The correct calculation should be `Math.abs(originalImagePPI / item.matrix.mValueA);`, the problem is, I am not aware of a native way to get the original file ppi information from the Illustrator API. You can probably use BridgeTalk and Photoshop to get it but that would not be fun. Obviously, Ai has the information since it's displayed in the Document Info palette, I just don't think it is exposed via the API.
Copy link to clipboard
Copied
Hello jduncan,
thank you for the detailed answer! So it is about the PPI parameter - the formula should be as you said originalImagePPI / scaling factor. I was mislead by the idea that the originalImagePPI should be the document PPI (that is why i've used 72) since the document can be 400x600 dimensions and we put image with way more pixels within (3000x3000 in this case). Anyway, unfortunately I cannot retrieve such data neither from XMP metadata nor I am able to integrate the script with BridgeTalk along with Photoshop. Probably I should think about more intuitive way of calculating the pixels based on the answer bellow.
Thank you so much!
Copy link to clipboard
Copied
As you change the scale, the effective resolution goes in the opposite direction. If you scale an image up to 1.33x%, the resolution drops by 25%. If you scale the image down to 50%, the resolution increases by 200%.
Unless I'm misunderstanding what you want, PPI should be a simple native pixel width / layout width. Height should be the same PPI unless the image is distorted. 72 pixels per inch does not come into play for PPI. For example: The original resolution of 3000 pixels at a width of 10 inches would be 300 ppi; at 5 inches, it would be 600 ppi; at 20 inches, it would be 15o ppi.
You can check the image info in Acrobat with the Print Production tools:
Copy link to clipboard
Copied
Hello David Creamer,
thank you for the provided detailed reply!
I was mislead by the idea that the originalImagePPI should be the document PPI - my idea was if the document is 72 PPI it should not be possible to have an item with higher resolution. Anywasy, that was pretty dumb idea. So how can I improve my formula based on the assumption that the scaling factor is increasing whem the image is down sized without the information about the PPI?
Thank you so much!
Copy link to clipboard
Copied
Using only A and D from the matrix will not be right if the element is rotated.
Copy link to clipboard
Copied
I guess this add additional overhead for the calculation formula 😄 . Thank you for the reminder!
Copy link to clipboard
Copied
Yes, I think this is a serious omission to the scripting API. I have just lodged a feature request to provide access to the Links Info, which includes PPI, pixel dimensions and scale/rotation. Please vote on it.
- Mark