11 Replies Latest reply on Jul 8, 2016 1:20 PM by ChrisDLR

    How to control the output size when exporting images from an InDesign Document?

    [Eric B] Level 1

      I have a script that loop through the document images and write them to the disk, but I would like to know how to control the output size of the images. Right now images seems to be exported the same size as their source, but with the exception where smaller images are getting up-scaled.


      var doc = app.activeDocument;
      var images = doc.allGraphics;  
      var documentPath = doc.filePath;
      
      app.jpegExportPreferences.jpegColorSpace = JpegColorSpaceEnum.RGB;
      app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.MAXIMUM;
      app.jpegExportPreferences.exportResolution = 300;
      
      for(var i=0; i < images.length; i++){
        filename = documentPath + "/image_" + (i+1) + ".jpg";
        var imageFile = new File(filename);
        images[i].exportFile(ExportFormat.JPG, imageFile, false);
      }
      
      

       

      The same question was asked on stackoverflow, but I was told it was not possible, is this true?

      extendscript - How to control the output size when exporting images from an InDesign Document? - Stack Overflow

        • 1. Re: How to control the output size when exporting images from an InDesign Document?
          Jump_Over Level 5

          Hi,

           

          Using your script (or any other) you are able to save a graphic to another file (let say copy it) with chosen properties.

          However you are not able to reach higher quality than stored in original file.

           

          So setting properties you are able to control output but with that strong limitation.

           

          What do you mean by "output size"? Kilobytes? Heigh and width?

           

          Jarek

          • 2. Re: How to control the output size when exporting images from an InDesign Document?
            [Eric B] Level 1

            Hi Jarek,

             

            Sorry for the confusion. What I'm looking for is to control the width and height of the image. Currently image are inserted in the document as is, therefor big images are downscale in the document to fit, but the source is unchanged. When exported, for HTML purpose, we would like to either (1) keep the dimension of the image as per the source, or (2) keep the same dimension as it is shown in the document, or (3) in all case have all images with a maximum width of 650px.

             

            How do I use ExtendScript to control the dimension?  There doesn't seem to be any export property to do so.

             

            Thanks,

            Eric

            • 3. Re: How to control the output size when exporting images from an InDesign Document?
              Jump_Over Level 5

              Hi,

               

              You could export (JPG format) either graphic (1) or its container (2) to reach original or scaled size.

              In case of specific size (3) in px it could be export of resized container or BridgeTalk involved to run some Photoshop codes (needs to run Photoshop).

               

              Jarek

              • 4. Re: How to control the output size when exporting images from an InDesign Document?
                [Eric B] Level 1

                Thanks Jarek, I think I am on the right track.

                 

                After some investigation I have found that option (1) and (2) seems to be providing the same result.  If you want your image to be the same size as the source you have to specify its exportResolution to be the same as the image, otherwise it will be the size of its container.

                 

                var doc = app.activeDocument;
                images = doc.allGraphics;
                documentPath = doc.filePath;
                
                app.jpegExportPreferences.jpegColorSpace = JpegColorSpaceEnum.RGB;
                app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.MAXIMUM;
                
                for(var i=0; i < images.length; i++){
                  app.jpegExportPreferences.exportResolution = images[i].actualPpi[0]; //Commenting this line will output the image with the same dimension as the container.
                  filename = documentPath + "/Image_" + (i+1) + ".jpg";
                  var imageFile = new File(filename);
                  images[i].exportFile(ExportFormat.JPG, imageFile, false);
                }
                

                 

                Now I will be investigating the (3) BrideTalk option.  I have successfully executed an "Hello World" in Photoshop using Bridgetalk in InDesign and I will explore it from there.  One observation I made is that it start Photoshop, do you know if it is possible to run it in the background without the user noticing it?

                • 5. Re: How to control the output size when exporting images from an InDesign Document?
                  Jump_Over Level 5

                  [Eric B] napisał(-a):

                  ...do you know if it is possible to run it in the background without the user noticing it?

                  I am afraid not.

                  But if you would go the way with resizing container before export (no BridgeTalk) - possibly yes.

                   

                  Jarek

                  • 6. Re: How to control the output size when exporting images from an InDesign Document?
                    [Eric B] Level 1

                    Damn I love collaboration.  This actually a very good idea, resize the container if needed when running the export.

                     

                    Thank you!

                    • 7. Re: How to control the output size when exporting images from an InDesign Document?
                      Peter Kahrel Adobe Community Professional & MVP

                      Eric,

                       

                      To check if an image was resized, you can check its scale:

                       

                      if (myImage.horizontalScale !== 100) {

                         // image was rescaled

                      }

                       

                      If there's any chance that images are resized non-proportionally, the check the verticalScale too.

                      To undo scaling, set the scale to 100.

                       

                      Peter

                      • 8. Re: How to control the output size when exporting images from an InDesign Document?
                        [Eric B] Level 1

                        Hi Peter,

                         

                        Even though my original image is 1920x1080 when placed in the document it's automatically scaled down to 460.8x259.2.  If I look at both horizontalScale and verticalScale property they both show 100.

                         

                        How can I bring it back or place it to its original size?

                         

                        Thanks,

                        Eric

                        • 9. Re: How to control the output size when exporting images from an InDesign Document?
                          Jump_Over Level 5

                          Hi Eric,

                           

                          Narrow it pls - which object are you talk about

                          1. graphic

                          2. graphic's container

                           

                          depends on what is selected - hori/vert scale can show a different values

                           

                          Jarek

                          • 10. Re: How to control the output size when exporting images from an InDesign Document?
                            Laubender Adobe Community Professional & MVP

                            Hi Eric,

                            and there is actualPpi and effectivePpi for the Image class, that will return an array of numbers for pixels per inch.

                             

                            The value array length is always 2.

                            If all numbers in the array are the same, the image is proportionally scaled.

                             

                            If the values of actualPpi and effectivePpi are the same, the image is proportionally scaled to 100%.

                             

                            Uwe

                            • 11. Re: How to control the output size when exporting images from an InDesign Document?
                              ChrisDLR Level 1

                              I'm not sure if this is the same issue, but I found when I create pages as containers for a web banner at the pixel dimension they need to be and export the file at 72dpi as png or jpg, that it has the proper dimensions and resolution but the file size is that of the linked source art, which is generally very large.

                               

                              I use InDesign to do web banners because I am required to do hundreds of them with only minor text variations and wildly varied dimensions, but when exporting them at 72dpi and the proper pixel dimension means the file size can vary between 1 and 8mb for a web banner using the same source artwork, it makes it unusable on most sites and cannot be downsampled in photoshop after the fact with a macro or something like that because it would alter the dimensions and resolution  and knock them out of spec, since they're already fixed at 72dpi and the proper dimensions. The only solution I've found is that reducing the size of the original will alter the output file size, but doing so will make some of the more drastic dimensions (the very long or very tall ones that have to zoom into the artwork to be usable) to be disproportionally pixellated compared to the others. I'd make different versions of the artwork in photoshop for the different sizes, but that defeats the purpose I had to resort to using InDesign in the first place.

                               

                              Is there some setting I'm ignoring or solution I'm not seeing?