12 Replies Latest reply on Sep 19, 2017 6:41 PM by jeanief79303961

    Exporting image coordinates and size

    Roger Shapland

      I'd like to be able to export image position and percentage size for all pictures in a document (the purpose is to import this information into a database to facilitate autocreation of the douments later on), I've done this before for Quark files by processing the report files but InDesign doesn't have this information. I'm working with InDesign CS5 on OSX and have very little experience of AppleScript - I've had quite a good browse around but to no avail, any help would be greatly appreciated.

        • 1. Re: Exporting image coordinates and size
          Roger Shapland Level 1

          Hello, not sure of the correct etiquette here, but I can get the information I want from exporting as IDML and pulling the image data from the XML in 'Spreads' - so no need for any scripting etc. Let me know if I should remove this post or leave it for others.

          • 2. Re: Exporting image coordinates and size
            Muppet Mark Level 5

            AppleScript is NOT your only scripting option like it is/was in Quark… If IDML works for you then all is fine… But you have more options to do this here… etiquette is that the same as forumdecorum? Leave it… it be out of sight in a day…

            • 3. Re: Exporting image coordinates and size
              [Jongware] Most Valuable Participant

              Generating a report for images has been done hundreds of times before But of course, never exactly the way you want it to.


              This Javascript is based on one I wrote for a similar request; it only needed minor tinkering to fit your purpose.


              app.activeDocument.viewPreferences.rulerOrigin = RulerOrigin.PAGE_ORIGIN;
              list = [];
              imgs = app.activeDocument.allGraphics;
              unitname = getCurrentUnit();
              for (i=0; i<imgs.length; i++)
              h = imgs[i].parent.geometricBounds[2] - imgs[i].parent.geometricBounds[0];
              w = imgs[i].parent.geometricBounds[3] - imgs[i].parent.geometricBounds[1];
              left = imgs[i].parent.geometricBounds[1];
              top = imgs[i].parent.geometricBounds[0];
              scale = roundMe(imgs[i].horizontalScale,1);
              // some fair rounding
              switch (unitname)
                case 'in':
                 w = roundMe(w, 3);
                 h = roundMe(h, 3);
                 left = roundMe(left, 3);
                 top = roundMe(top, 3);
                case 'cm':
                 w = roundMe(w, 2);
                 h = roundMe(h, 2);
                 left = roundMe(left, 2);
                 top = roundMe(top, 2);
                 w = roundMe(w, 1);
                 h = roundMe(h, 1);
                 left = roundMe(left, 1);
                 top = roundMe(top, 1);
              list.push (imgs[i].itemLink.name+'\t'+'('+left+','+top+')'+'\t'+w+' x '+h+' '+unitname+'\t'+scale+'%');
              // alert (list.join('\r')); exit();
              defaultFile = new File (Folder.myDocuments+"/"+app.activeDocument.name.replace(/\.indd$/i, '')+".txt");
              if (File.fs == "Windows")
              writeFile = defaultFile.saveDlg( 'Save report', "Plain text file:*.txt;All files:*.*" );
              writeFile = defaultFile.saveDlg( 'Save report');
              if (writeFile != null)
              if (writeFile.open("w"))
                writeFile.encoding = "utf8";
                writeFile.write (list.join("\r")+"\r");
              function roundMe(val,to)
              var t = 1;
              while (to-- > 0) t *= 10;
              return Math.round(val*t)/t;
              function getCurrentUnit ()
              switch (app.activeDocument.viewPreferences.horizontalMeasurementUnits)
                case MeasurementUnits.POINTS: return "pt";
                case MeasurementUnits.PICAS: return "pt";
                case MeasurementUnits.INCHES: return "in";
                case MeasurementUnits.INCHES_DECIMAL: return "in";
                case MeasurementUnits.MILLIMETERS: return "mm";
                case MeasurementUnits.CENTIMETERS: return "cm";
                case MeasurementUnits.CICEROS: return "c";
                case MeasurementUnits.AGATES: return "ag";
                default: alert ("Oh, come on!"); exit(0);
              1 person found this helpful
              • 4. Re: Exporting image coordinates and size
                Roger Shapland Level 1

                Hi Jongware, that works a treat - I wasn't expecting a fully working solution, many thanks and let me know if a contribution would be in order!

                • 5. Re: Exporting image coordinates and size

                  this is great! Is there anyway to do this for text boxes?

                  To get their position and angle?


                  Thanks in advance.

                  • 6. Re: Exporting image coordinates and size

                    Just stumbled on this script and it is amazing! Any chance this exported data could then be re-applied to another document through an additional script (ex. apply sizing to images, apply x.y positioning to images)? This would be hugely helpful for yearly catalog production. Let me know if this makes sense or not.

                    • 7. Re: Exporting image coordinates and size
                      Roger Shapland Level 1

                      Hiya, if you're doing catalog work then you'd be better taking the data from one document and putting it in a database so that you can export it all as tagged text into InDesign - have a look at Em Software's Xtags. Let me know if you want to know more.

                      • 8. Re: Exporting image coordinates and size
                        Laubender Adobe Community Professional & MVP

                        @Jongware – it's quite a while since you posted this code.

                        Just as a sidenote:

                        A script that is operating with the geometric bounds could lead to false results, if the object is rotated or sheared or both…


                        Marc Autret pointed this out at his blog at:




                        and suggested a different approach in the section


                        "Getting Width/Height from the Inner Coordinate Space":


                        the "ultimate getDims() function".


                        The function returns an array with two numbers for width and height in points and could be expanded to return the numbers in the required measurement unit.



                        • 9. Re: Exporting image coordinates and size
                          lazycarpenter Level 1

                          Thanks for the tip! Will look into the Em solution. Though I will still pursue a scripting solution.

                          • 10. Re: Exporting image coordinates and size
                            lazycarpenter Level 1



                            Kicking this thread back to life.


                            Could the coordinates exported from the above script (x,y) be combined with a script like the one below which applies the image size coordinates to specific Links in the document? The result being certain page items (images) placed on the page acutomatically based on the x,y corrdinates provided.



                            // <- Scale Images
                            var doc = app.activeDocument,
                                i, l, link, target, pageItem, height, scale, matrix, newHeights;
                            app.transformPreferences.whenScaling = WhenScalingOptions.APPLY_TO_CONTENT;
                            doc.viewPreferences.horizontalMeasurementUnits = doc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.POINTS;
                            newHeights = {
                            "Image01": 0.4,
                            "Image02": 0.45,
                            "Image03": 0.5,
                            var count = 0;
                            for (i = 0, l = doc.links.length; i < l; i++) {
                                link = doc.links[i];
                                var size = null;
                                for (var prefix in newHeights) {
                                if (link.name.substring(0, prefix.length) == prefix) {
                                        size = newHeights[prefix];
                                if (size) {
                                    pageItem = link.parent.parent;
                                    height = pageItem.visibleBounds[2] - pageItem.visibleBounds[0];
                                    target = new UnitValue(size, 'in').as('pt');
                                    scale = target / height;
                                    matrix = app.transformationMatrices.add({horizontalScaleFactor: scale, verticalScaleFactor: scale});
                                    pageItem.transform(CoordinateSpaces.INNER_COORDINATES, AnchorPoint.TOP_LEFT_ANCHOR, matrix);
                            alert("Updated " +count + " links");
                            // -  Reset Rulers to Inches
                            doc.viewPreferences.horizontalMeasurementUnits = doc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.INCHES;



                            I am stumped, any help is HUGELY appreicated.

                            • 11. Re: Exporting image coordinates and size
                              Oriup Level 1

                              Dear Jongware,


                              Can I get only those names with percentage list which is reduced or increased image size?





                              • 12. Re: Exporting image coordinates and size

                                Could you point me in the right direction of understanding what units the XY populates from this amazing script? Also, would it be possible to add what page number the art is on?