4 Replies Latest reply on Jul 24, 2012 10:31 AM by lazycarpenter

    Image size scripting help...

    lazycarpenter Level 1



      I am a novice scripter and need help with a script I am building for a 1000+ page catalog I am working on.


      In short I have multiple ID CS3 documents with over 1000 images all set to a particular size (.25" for example).


      I need to resize each identical link to a specific size throughout the whole document  - for example:


      acme_logo.eps ---> original size H = .25"    need to resize all elements named acme_logo.eps  to H = .35"


      Obviously doing this one by one is very time consuming and a script would be very helpful.


      Below is my VERY rough start:



      app.activeDocument.stories.everyItem().PageItem.images.Link.everyItem().name  = "acme_logo.eps". size = ".35 in);



      Can anyone help or offer insight? Your help is greatly appreciated.

        • 1. Re: Image size scripting help...
          absqua Level 4

          I think this will do what you want:


          var doc = app.activeDocument,
              i, l, link, target, pageItem, height, scale, matrix, newHeights;
          app.transformPreferences.whenScaling = WhenScalingOptions.APPLY_TO_CONTENT;
          doc.viewPreferences.horizontalMeasurementUnits = doc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.POINTS;
          newHeights = {
              "acme_logo.eps": 0.35,
              "IMG_1334.jpg": 0.75,
              "IMG_1335.jpg": 1,
              /// ...
          for (i = 0, l = doc.links.length; i < l; i++) {
              link = doc.links[i];
              if (link.name in newHeights) {
                  pageItem = link.parent.parent;
                  height = pageItem.visibleBounds[2] - pageItem.visibleBounds[0];
                  target = new UnitValue(newHeights[link.name], 'in').as('pt');
                  scale = target / height;
                  matrix = app.transformationMatrices.add({horizontalScaleFactor: scale, verticalScaleFactor: scale});
                  pageItem.transform(CoordinateSpaces.INNER_COORDINATES, AnchorPoint.CENTER_ANCHOR, matrix);


          You can fill in the newHeights dictionary with other link names and target heights (in inches).


          See the getting-started page at http://forums.adobe.com/docs/DOC-1061 . I recommend Peter Kahrel's book, which is linked on that page, to start with.



          • 2. Re: Image size scripting help...
            lazycarpenter Level 1

            WOW! This is amazing! You are a Hero!!!


            If I had to be greedy and ask one more question it would be to set the anchor point to the upper left corner so they do not shift to the left when applying. Does this make any sense? I can make an example if needed. THis would be HUGE!!!


            Also thanks for the resources. I will definetly be digging deeper into scripting as these are invauable to a catolog production team.

            • 3. Re: Image size scripting help...
              absqua Level 4

              Glad to help. Simply change AnchorPoint.CENTER_ANCHOR to AnchorPoint.TOP_LEFT_ANCHOR in the pageItem.transform() call at the end.

              1 person found this helpful
              • 4. Re: Image size scripting help...
                lazycarpenter Level 1

                Wow. Soooo helpful!!!


                Are you able to provide further scripting help? I have a great deal of repetative tasks like this one that I could really use help on. I can eathier post on this forum or contact you in private (if o.k.?)


                Please let me know and thanks again.