8 Replies Latest reply on Jul 27, 2016 9:13 AM by Laubender

    Possible to use recompose to dynamically scale images?

    cchimi Level 2

      I have a script that places some images in a document. Sometimes the images are too big for the textframe and cause the text to become overset. I would like to handle this by scaling the image down until the text that follows it is no longer overset, but the text does not seem to recompose after the image is scaled. Here is some rough code:

       

      var myDoc = app.activeDocument;
      var mySel = app.selection[0];
      var myScale = 60;
      var myRect, myImg, myParent;
      
      
      if (mySel instanceof Graphic){
          myRect = mySel.parent;
          myImg = mySel;
      }else {
          myRect = mySel;
          myImg = myRect.graphics[0];
      }
      
      if (myRect instanceof Rectangle){
          myParent = myRect.parent;
          while (!(myParent instanceof Story || myParent instanceof Application)){
              if (myParent.hasOwnProperty("parentStory")){
                  myParent = myParent.parentStory;
              }
              else{myParent = myParent.parent;}
          }
          if (myParent instanceof Story){
              while (myParent.overflows == true && myScale > 5){
                  myScale -= 5;
                  myRect.horizontalScale = myRect.verticalScale = myScale;
                  myParent.recompose();
                  $.writeln(myRect.horizontalScale);
              }
          }
      }
      

       

      To run it you would need to place an image in a text frame, scale it so that it is selectable, select it (or the rectangle it sits in, really), and then scale it up so that it no longer fits. What I see when I do this is that the scale reduces as I would expect, but it always gets all the way to 5, even though I know the image is viable at a higher scale. Recompose seems to have no effect. I've also tried scaling the graphic itself and then fitting the rectangle to it; no difference.

       

      Is this just a bug in recompose? Or am I misunderstanding something about how ID handles image scaling? I do have the Adjust Scaling Percentage option selected under Preferences > General > Object Editing (frankly, I'm not sure I understand the other option, but this seems to be the correct one for what I want). I'm using CC 2015 and haven't been able to test in any other versions. Any insight would be appreciated.