11 Replies Latest reply on May 20, 2015 9:16 AM by AS Scripter

    Get Image Dimension Before Place on Pages

    Vinícius Amaral Level 1

      Hello there,


      How are you doing?


      I need get the image dimensions before place on Pages.

      So when I bring it for the place gun, I need a way to discover the width and height of the image.

      If you look at link info in links pallet, it is possible find this information.


      Sem título.png


      I´ve tried many ways to do it, but I have nothing as I really need.

      I´ve accessed the XMP data, but the images that I´m using don´t have the information there.

      Anyone has a way to do it?


      Thanks and best regards.

        • 2. Re: Get Image Dimension Before Place on Pages
          Vinícius Amaral Level 1



          Thanks for your answer, but I´ve tried everything before.

          I can read the XMP of my images, but they don´t show me the dimensions.

          The other links ask me to import the image to page, but I can´t do it.

          I have to know the dimensions and check if the image is vertical or horizontal before import.

          If I do not know before, I will have to import it for my page, check the bounding box, erase the images and import again inside the correct frames.

          It is fast for one image, but it´s not fast for 3 or 4 thousands.

          Do you know if there is a way to do it?

          • 3. Re: Get Image Dimension Before Place on Pages
            [Jongware] Most Valuable Participant

            But you can resize an image right after importing. No need to "erase and import again".


            Can you tell what you are doing instead of how you are doing it?

            • 4. Re: Get Image Dimension Before Place on Pages
              Vinícius Amaral Level 1

              Mr. Jongware

              First of all, I wanna say that you are my idol.

              I always say good things about you in my lectures here in Brazil.

              You are amazing and your documentation help us a  lot. I think it have to be the official reference of Adobe.

              Please, update the site for versions like CC and CC 2014.

              It is a pleasure ask you something directly.


              The job

              For a better understatement, I´m developing a script to create books with text and image.

              I have many ready templates to use for each page.

              To choose one template for the next page, I need to know how many images horizontals and verticals I will have.

              If I find 5 verticals and 7 horizontals images I will use one kind of template, but if I find another number I will have to choose another one.


              Why I don´t resize

              Because the ready template has a customized items with or without object styles applied, and apply all properties of then spend too many time processing.

              One book has thousand of images, and the script will process a lot of books dally.

              If I read the image dimensions before insert on page, I can insert the image in the correct place without a new import or a re-size.


              Do you think is there a way to do it only using pure JavaScript?

              I´m asking because I will try develop something in C++ just to send the dimensions for the JS.

              I don´t have any experience in C++, so I will spend to many time to do it.


              Thanks for your attention.

              • 5. Re: Get Image Dimension Before Place on Pages
                [Jongware] Most Valuable Participant

                Thank you for your kind words!


                It seems not possible to get the size of an image before it gets placed. The usual way - geometricBounds - does not work because this only measures the size of an actual object inside a document. The Graphics properties of images provides lots of numbers, but none of them specify the size, in pixels or otherwise.


                Here is a workaround: place the selected images and then measure. To move them 'back' into the Place Gun, I then remove them again and finally load the entire image list into the Place Gun. I think (/hope) it only takes marginally longer to load the images twice.


                The script needs to know what images are selected, so there are two options:

                1. manually load the Place Gun and then run a script (which places the images, removes them again, and reloads the place gun); or

                2. run a script that lets you select images as usual, and then it takes over. That is what the following script does.


                (Warning: I'm behind a Mac right now and could not test the file selector for Windows! If all else fails, just remove the "smart" extension list shuffling and replace it with "*.*"...)


                At the very bottom of the script, you'll see a simple alert that shows width and height of each of the images. At that point, you can inspect their orientation and determine which master page to use. For clarity I rounded the image sizes; remove the "Math.round" if you need the real dimensions.


                Some further ideas: the script starts by looking in the folder "myDocuments". You can make it look in another default folder, or in the folder in which your current document is saved (if it already has been saved), or any other useful location.


                If you found a good match for a master page, you can apply it automatically to your current page. Since the script ends with the place gun already loaded, you can then click right away in the correct boxes.


                If you want to place the files based on their orientation (say, you want all Portrait images first, and then all Landscape ones), you can re-order the file list just before reloading the Place Gun. See tomaxxi's QuickTip: Loading Files to PlaceGun | IndiSnip [InDesign® Snippets] which sorts on creation date - I did not try but I imagine you can sort on orientation as well.



                var extensionlist = [ 'pdf', 'png', 'tif', 'tiff', 'jpeg', 'jpg', 'png' ];
                if (File.fs == "Windows")
                  selector = [];
                  for (i=0; i<extensionlist.length; i++)
                  selector[i] = '*.'+extensionlist[i];
                  selector = selector.join(',');
                  imglist = Folder.myDocuments.openDlg( 'Select images', "Image:"+selector+";All files:*.*", true);
                } else
                  imglist = Folder.myDocuments.openDlg( 'Select images',
                  selector = new RegExp('\\.('+extensionlist.join('|')+')$', 'i');
                  return file instanceof Folder || (!(file.hidden) && file.name.match(selector));
                  }, true );
                if(imglist != null)
                  var sizelist = [];
                  for (i=0; i<imglist.length; i++)
                  r = app.activeDocument.pages[0].place(imglist[i], [0,0])[0];
                  sizelist.push ([Math.round(r.geometricBounds[3]-r.geometricBounds[1]),
                  app.activeDocument.placeGuns.loadPlaceGun(imglist, false);
                  alert (sizelist.join('\r'));
                • 6. Re: Get Image Dimension Before Place on Pages
                  S Hopkins Adobe Community Professional

                  Just a thought: If you are on a Macintosh there is a handy application: "Image Events". One idea might be to use Image Events to examine the files. Then, maybe using Finder, you could organize the files (perhaps by giving the files a tag--or label index). Finder file tags (label indexes) give the file a color marker which can be used to visually classify files. Otherwise, within a script you could have Finder return the number of chosen files that have a label index of 1 or 2.  Simple example for establishing file tags follows:

                  set folderRef to choose folder

                  set folderStr to folderRef as string

                  set fileList to list folder folderRef without invisibles

                  repeat with i from 1 to length of fileList

                    tell application "Image Events"

                    set fileRef to (folderStr & item i of fileList)

                    set fileOpen to open file fileRef

                    set fileDim to dimensions of fileOpen

                    close fileOpen

                    end tell

                    if item 1 of fileDim > item 2 of fileDim then

                    set theIndex to 1


                    set theIndex to 2

                    end if

                    tell application "Finder"

                    set label index of file fileRef to theIndex

                    end tell

                  end repeat

                  • 7. Re: Get Image Dimension Before Place on Pages
                    Laubender Adobe Community Professional & MVP

                    @Jongware—just a warning: I remember cases where InDesign is placing the images in "landscape" (horizontal) mode and PhotoShop is opening them in "portrait" (vertical) mode. Always images that never were opened and saved in PhotoShop; images that were directly copied over from the camera to the computer and placed in InDesign. So I strongly recommend, that the images to place should be pre-processed first to find out the right orientation.


                    It could be a good idea to open the images first in PhotoShop, reading out the dimensions, closing, maybe even saving the file and placing then.

                    There might be also a problem with detecting the right color profile from InDesign's side. I recall a case where PhotoShop will detect a color profile and InDesign is thinking there is no profile attached to the image. Also with images that never were opened in PhotoShop.


                    I'll see, if I can find some older threads on these topics and issues and add some links later.


                    @Vinícius—For the coding side with ExtendScript see some threads here in the scripting forum what Kasyan Servetsky is doing with BridgeTalk to reach PhotoShop from InDesign.

                    Or download some of his scripts related to InDesign/PhotoShop on his website and analyze the code:




                    • 8. Re: Get Image Dimension Before Place on Pages
                      Vinícius Amaral Level 1

                      Dear Jong


                      Thanks for your answer,

                      I´ve seen your script and that is a good deal.

                      It´s not that I really want, but is the best possible way to do it.

                      I´m just thinking about, work with some undo modes based on your script, but first I will try to develop a Script for Adobe Bridge to create some XMP tags or markups based on their sizes.

                      When I finish it, I send back for your validation.


                      Thanks a lot for your help.

                      It was a great pleasure have your suport.

                      • 9. Re: Get Image Dimension Before Place on Pages
                        Vinícius Amaral Level 1

                        Dear Ms. Hopkins


                        Thanks for your answer.

                        I´ve read your book many times (Automating Adobe InDesign CS4 with ExtendScript).

                        Is the most simple and complete way to learn JS to Indesign. Thanks, It helps me a lot.


                        I will use it both PC and Mac, but I will read about the recommended solution.

                        Getting your idea, I can use the Picasa, for example.

                        I think it can export all properties of image using a XML file.

                        I will study a little bit more and send you my results.

                        Thanks a lot.

                        • 10. Re: Get Image Dimension Before Place on Pages
                          Vinícius Amaral Level 1

                          Dear Laubender


                          Thanks for your support.

                          A batch processing in Bridge just will help me if it uses the image metadata.

                          If the Photoshop opens each image, I will spend more time than I have.

                          I think will be more fast import and re import in InDesign.


                          I will study a little bit more about this challenge.

                          I send an answer in a few days.


                          Thanks again.

                          • 11. Re: Get Image Dimension Before Place on Pages
                            AS Scripter Level 1

                            You might also consider first running a separate shell command batch process on all files and putting the image dimensions, color mode, bit-depth, etc, into a database such as FileMaker which can then run the place scripts, or renaming copies of the files with the desired info embedded in the filename which would allow your place script to parse the filename and make the necessary decisions.