Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Retreiving Embedded Images Information

Community Beginner ,
Apr 21, 2011 Apr 21, 2011

I have a two-part question.  One, I need to know why Illustrator displays embedded images at 72 dpi.  Two, how can I retreive an image's correct size and/or resolution?  Illustrator has the information contained somewhere, I see it being displayed in this window:

screenshot.jpg

Is there a reason it returns the incorrect "Dimensions" when I ask for the width of a rasterItem?

I'm using ExtendscriptToolkit 2 to write jsx to control Illustrator CS4.

Thank you!!!

TOPICS
Scripting
3.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Apr 21, 2011 Apr 21, 2011

The RasterItem properties contain some of these items, but resolution, for instance, seems to be missing.

Illustrator has the information contained somewhere, I see it being displayed in this window ...

There is no immediate link between what Illustrator can do and display in the User interface and what's possible with scripting. Of course Illustrator is aware of the dimensions, otherwise it couldn't display them in this info panel. But it does not mean you "therefore" can read them with a script.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 21, 2011 Apr 21, 2011

Is your assertion that it's illogical to assume that Illustrator would be able to return properties it uses in its interface?  I don't mean to assume that there is, but if there was a way, I'd expect someone here to know how to do it... or at least a reason for why it can't be done.  Either way, snarky comments ain't really solvin' mah problems, know what I mean?

More importantly would be understanding why Illustrator displays embedded images at the size it does.  Maybe then I could do some calculations to sort of reverse engineer out the actual dimensions.

p.s. Why did you put "therefore" in quotes?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 21, 2011 Apr 21, 2011

There are a lot of the application which is hidden to scripting, especially those things handled by .aips (Adobe Illustrator Plugins) in the GUI. That's just the way things are. Illustrator has always reported images as a percentage of actual ppi when not at 72. If you place a 300ppi image and look at the info in the links panel, it will be reported as 24%. It's not actually scaled to 24% but it is reported as such.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 21, 2011 Apr 21, 2011

24% because 72 is 24% of 300, right?  Is there a reason Illustrator displays stuff at 72dpi?  I feel like there has to be a way to calculate this bad boy.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 21, 2011 Apr 21, 2011

Snarky ..

"Therefore" because it seemed you assumed that Illustrator can show you the info and "therefore" it should be scriptable. There is no such link (snarky or not, that's a fact).

What I meant is: all properties that are exposed to scripting are described under RasterItem properties, and that's all you can read -- there is no hidden stuff that gets available with sleight of hand & trickery.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 21, 2011 Apr 21, 2011

My experience with coding has been the exact opposite, dude.  There's always a way.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 22, 2011 Apr 22, 2011

Noah… are you sure that your dimensions are wrong…? Illustrator is giving you the height & width of the item in 'points' measurement… as it does with every thing… You should be able to look at it's matrix if you need to know scaling transform values…

This is an unusual approach that will give you the 'effective' resolution of an image… actual res/scaling factor… It traces the image so I would expect this to be slow… I've not used it with any big images…

#target illustrator var docRef = app.activeDocument; // We are expecting at least 1 raster item alert('Image: '+objectResolution(docRef.rasterItems[0])+' dpi'); function objectResolution(obj) {      if (obj.typename == 'PlacedItem' || 'RasterItem') {           var objTrace = obj.trace();           app.redraw();           objTrace.tracing.tracingOptions.resample = false;                     var objRes = Math.round(objTrace.tracing.imageResolution);           objTrace.tracing.releaseTracing();           app.redraw();                return objRes;      } else {           alert('This is the wrong type of object?');           return false;      } }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 22, 2011 Apr 22, 2011

Mark, I'm unfamiliar with the tracing or redraw functions, but I'll start playing with them.  It looks like, maybe if I make a copy of the image then I could delete it after the trace rather than having to redraw it?  As long as I can scoop out the resolution property first, right?  This is brilliant, man!

Also, because I've heard it mentioned before but can't find any information about it, would you mind giving me an explanation of the transformation matrix, pleeease? 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 22, 2011 Apr 22, 2011

"Noah… are you sure that your dimensions are wrong…?"

Actually, I meant to address that in my first post.  The "Dimensions" numbers were the same in points and pixels (I don't know why) and I didn't change the units preference back to pixels before taking the screenshot. 

Illustrator seems to hold the inches size, but shrinks the points size down to a 1:1 proportion with pixels... can anyone think of an equation to reverse-calculate the actual size in pixels with that assertion?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 22, 2011 Apr 22, 2011

The "Dimensions" numbers were the same in points and pixels (I don't know why)…

This is because using pixels is based on 72dpi and there are also 72 points in an inch… Using live trace is a bit over the top since we are only reading a value from the trace then throwing the trace away… This was more to see it the method worked which it does… If you know the path then there are ways to read the sizes from the file too… This was more of a last resort for checking images where you don't have access to the original image…

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 22, 2011 Apr 22, 2011

I'm starting to feel a little last-resort, actually.  If it gets me access to the resolution property I'm down to try tracing the object, but of course I'll do an easier maneuver. 

Now I understand why the points to pixel conversion was coming out that way, what I don't get is why Illustrator displays everything at 72 dpi.  If there's a solid reason maybe we can begin to connect a dot to the size in inches.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 26, 2011 Apr 26, 2011

So, it's working!!!  It's not what I wanted to come away with but it's WORKING!!!  Thanks, Muppet Mark!

######################

#target illustrator;

var resolution = detectLowRes(docRef);

function detectLowRes(docRef){

     for (var num=0; num<docRef.rasterItems.length; num++){

          var resolution = objectResolution(docRef.rasterItems[num]);

     }

     return resolution;

}

function objectResolution(obj) {

     // 1. copy\paste obj in new document

     obj.selected=true;

     copy();//

     var docRef2 = documents.add(DocumentColorSpace.RGB, 1500, 1500, 1); // new doc RGB

     paste(); //

 

     // 2. trace obj

     var objTrace =obj.trace();

 

     // 3. extract resolution property

     objTrace.tracing.tracingOptions.resample = false;      

     var objRes = Math.round(objTrace.tracing.imageResolution);

     objTrace.tracing.releaseTracing();

 

     // 4. delete temp document

     docRef2.close(SaveOptions.DONOTSAVECHANGES);

 

     // 5. return resolution

     return objRes;

}

alert("Mind = Blown: " + resolution + " dpi");

######################

If anyone can see a way to clean this up further please let me know.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 09, 2014 Oct 09, 2014

I tried to use your script and this error happened, can you tell why?

ERROR.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 09, 2014 Oct 09, 2014
LATEST

do you have an embedded image...plus, add this line

var docRef = app.activeDocument;

between these two

#target illustrator;

var resolution = detectLowRes(docRef);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines