5 Replies Latest reply on May 11, 2015 11:02 AM by [Jongware]

    Resize selected image to full page

    brown1982 Level 1

      Good day all,

       

      Could someone help me with a script. This script will do the following thing.

      The selected object (object anchord) scale to full page.

       

      Kind regards and Many thanks!

        • 1. Re: Resize selected image to full page
          brown1982 Level 1

          Please help, cause i cant get further than this, and probably this is not correct...

           

          for

            {

            app.activeDocument.mySelectObjects.fitPage [resize]????

           

            }

          • 2. Re: Resize selected image to full page
            [Jongware] Most Valuable Participant

            The correct order of doing this is:

             

            1. check if the selection is correct (only accept anchored objects)
            2. find the current page size
            3. make sure the anchored object options are applied
            4. adjust frame size
            5. adjust content size

             

            For point #5, you can choose between fitting the image into the page-sized frame proportionally (and then you usually want it centered) or out of proportion (so it fills the entire page). Make sure to disable/enable the correct lines in my script below.

             

            // check if anything is selected.
            // This can be '0','1', or more, but you can only select
            // one Anchored object at a time so that's all we want
            // to know.
            if (app.selection.length == 1)
            {
              // check if it is an anchored object. First, test object itself (image or frame)
              theObject = app.selection[0];
              // if you selected with the white arrow, you have its contents
              // so go up one 'item'
              if (theObject instanceof Graphic)
                theObject = theObject.parent;
              // now theObject holds the frame. Test if it's Anchored --
              // if so, its parent is Character (that is the single 'character'
              // inside the text that contains the object).
              if (theObject.parent instanceof Character)
              {
                // okay, we're good. 'theObject' is correct. Now, get the page size.
                // This can be 'parentPage' for CS5 and newer, for CS4 and older
                // you need to 'go up' your current text frame until you end up at a page
                // (or somewhere else :(). For now, I'll assume this is just a simple textframe
                // on a single page.
                // That is: [anchored object] -> [character] -> [textframe] -> [page]
                pg = theObject.parent.parentTextFrames[0].parent;
                // Now pg.bounds is the exact page size! Enable this line:
                // alert (pg.bounds);
                // to see it.
            
                // We're not done with the object. We need to make sure it's *floating*
                // and not in-line:
                theObject.anchoredObjectSettings.anchoredPosition = AnchorPosition.ANCHORED;
                theObject.anchoredObjectSettings.anchorPoint = AnchorPoint.BOTTOM_LEFT_ANCHOR;
                theObject.anchoredObjectSettings.horizontalReferencePoint = AnchoredRelativeTo.PAGE_EDGE;
                theObject.anchoredObjectSettings.verticalReferencePoint = VerticallyRelativeTo.PAGE_EDGE;
                theObject.anchoredObjectSettings.lockPosition = false;
                theObject.anchoredObjectSettings.pinPosition = false;
            
                // now change the frame size:
                theObject.geometricBounds = pg.bounds;
            
                // The contents needs to be scaled as well!
                // This can be one of two: fill (out of proportion), or
                // scale to largest (in proportion but not filled).
                // So use either this:
                theObject.fit (FitOptions.CONTENT_TO_FRAME);
                // or these two lines:
              //  theObject.fit (FitOptions.PROPORTIONALLY);
              //  theObject.fit (FitOptions.CENTER_CONTENT);
              } else
              {
                alert ("not an anchored object");
              }
            } else
            {
              alert ("bad selection");
            }
            
            
            
            • 3. Re: Resize selected image to full page
              brown1982 Level 1

              That look like a real Jongware script

              unfortunately i can't test it now, but i'll let u know !

              • 4. Re: Resize selected image to full page
                Oleh Melnyk Level 3

                in my case string

                pg = theObject.parent.parentTextFrames[0].parent;
                

                returns speread and script fails

                 

                replacing it with

                pg = app.activeWindow.activePage;
                

                helps, but script didn't count bleeds, and positon image with some offset

                 

                I'd like to have modified version of this script that will make selected [not ancored] image full page, counting bleeds.

                Or, maybe even 2 scripts: "fit selected image to page", and "fit selected image to spread"

                • 5. Re: Resize selected image to full page
                  [Jongware] Most Valuable Participant

                  Oleh, that is quite another direction than was asked my mr. Brown. You may want to ask in a new thread, or try it for yourself. The bulk of my script was to cater for the required correct anchor settings (as it turned out, the script needed to run under CS5, not '4, and needed even some more anchor settings).