11 Replies Latest reply on Mar 31, 2011 3:23 AM by BeriliaTubul

    [JS] image too big - resize

    BeriliaTubul Level 1

      Hi all,

       

      I import an XML file who can contain images.

      The problem is when an image is too long (and can't be contain in the textframe), it doesn't appear.

       

      I would like to resize it, but when I do imageTooLong.geometricBounds, I have an error. Which is not surprising.

       

      So, how can I resize imageTooLong?

       

       

      Thanks,

      Sophie

        • 1. Re: [JS] image too big - resize
          csm_phil Level 4

          Hi Sophie,

           

          i think you expected every inline images should scale in 100% and fit to frame, any way you have try this:

           

          var myDoc = app.activeDocument;

           

          for ( var s = 0; s < myDoc.stories.length; s++ ){
              var myStry = myDoc.stories[s];
              for ( var g = 0; g < myStry.allGraphics.length; g++ ){
                  myStry.allGraphics[g].horizontalScale = 100;
                  myStry.allGraphics[g].verticalScale = 100;
                  myStry.allGraphics[g].fit(FitOptions.FRAME_TO_CONTENT);
                  }
              }

           

          regards

          CSM_PHIL

          • 2. Re: [JS] image too big - resize
            BeriliaTubul Level 1

            Thank you, but it doesn't change change anything.

            • 3. Re: [JS] image too big - resize
              csm_phil Level 4

              Hi,

               

              can you give the snapshot because i flowed the xml file and i run the script above script its working fine.


              thanks,

              CSM_PHIL

              • 4. Re: [JS] image too big - resize
                BeriliaTubul Level 1

                Actually, I'm not authorized to put snapshots online (private project)

                 

                But there is something I should have say : Here is my XML :

                 

                I'm not sure it is useful but...

                • 5. Re: [JS] image too big - resize
                  csm_phil Level 4

                  Hi,

                   

                  i put the snapshot image

                   

                  before run the script just flowed the text for sample

                  Picture 1.png

                  after i run the above given the script it look like resize the 100% as i need see the below image

                   

                  Picture 2.png

                   

                  thx,

                  csm_phil

                  • 6. Re: [JS] image too big - resize
                    BeriliaTubul Level 1

                    Your image is not long enough. It's twice or more the width of the text frame.

                    I change the text to lorem ipsum. Here is what I have before your script, and after it's exactly the same...

                    Capture d’écran 2011-03-31 à 10.31.39.png

                    • 7. Re: [JS] image too big - resize
                      csm_phil Level 4

                      Hi,

                       

                      i think your snapshot look like image load into the table, if my guess its correct please use this script. i have join the table column extended the based on text frame width.

                       

                      var myDoc = app.activeDocument;
                      for ( var s = 0; s < myDoc.stories.length; s++ ){
                          var myStry = myDoc.stories[s];
                          for ( var g = 0; g < myStry.allGraphics.length; g++ ){
                              myStry.allGraphics[g].horizontalScale = 100;
                              myStry.allGraphics[g].verticalScale = 100;
                              myStry.allGraphics[g].fit(FitOptions.FRAME_TO_CONTENT);
                              }
                          }

                       

                      var myTables = myDoc.stories.everyItem().tables.everyItem().getElements();
                          for (var t = 0; t < myTables.length; t++) {
                                var myTableWidth = myTables[t].width;
                                var myTableColWidths = myTables[t].columns.everyItem().width;
                                var myTableParent = myTables[t].parent;
                                var myParentWidth = myTableParent.textFramePreferences.textColumnFixedWidth;
                                var myAdjustment = myParentWidth / myTableWidth;
                                for (var c = 0; c < myTables[t].columns.count(); c++) {
                                     myTables[t].columns[c].width = myTableColWidths[c] * myAdjustment;
                                     }
                                 }

                       

                       

                      thx

                      CSM_PHIL

                      • 8. Re: [JS] image too big - resize
                        BeriliaTubul Level 1

                        I'm sorry, nothing changed.

                         

                        I think the image is loaded, but even if I extend my text frame and the cell, it doesn't appear. (but the image is very big : 344 × 1595 px)

                         

                        Thank you for your help.

                        • 9. Re: [JS] image too big - resize
                          csm_phil Level 4

                          Hi,

                           

                          You have to change the percentage 100 to 30-50%, because the origianl image size very very big. now you check and let you know, so my guess is correct your image loaded in the table.

                           

                          thx,

                          csm_phil

                          • 10. Re: [JS] image too big - resize
                            BeriliaTubul Level 1

                            Thank you!

                             

                            It works now. I didn't understand what was horizontalScale and verticalScale ('cause I didn't know what scale was, i should have traduce it).

                             

                            Now I just have to improve this script to resize just the ones who need to and with the minimal percentage (I can do it alone, it should not be very complicated).

                             

                            Thank you again for your help

                            • 11. Re: [JS] image too big - resize
                              csm_phil Level 4

                              Hi Sophie,

                               

                              any way thanks for your reply, any way now you got the solution.

                               

                              thx

                              csm_phil