10 Replies Latest reply on Jun 25, 2006 8:35 AM by Tom Hersh

    Help with a Command script

    Tom Hersh
      Hello,
      Awhile back someone wrote the following script for me. The idea was to make a comman that would allow me to reduce an image down to 400 pixel width without loss of scale. I want to have a similiar command that will reduce a large image down to 400 pilel height without loss of scale. I fiddled with the command for width but can't get it to work for height. Can I get some help rewriting the following command to work for 400 pixel height? Thanks.
      // User Variables
      var width = 400;

      // Command
      var dom = fw.getDocumentDOM();
      var scale = width/dom.width;
      var height = dom.height * scale;
      dom.setDocumentImageSize({left:dom.left, top:dom.top, right:dom.left+width, bottom:dom.top+height}, {pixelsPerUnit:dom.resolution, units:dom.resolutionUnits});
        • 1. Re: Help with a Command script
          Level 7
          Tom,

          Go through the Batch process with the parameters you need and save the
          script on the last screen.

          File > Batch Process

          alex

          Tom Hersh wrote:
          > Hello,
          > Awhile back someone wrote the following script for me. The idea was to make a
          > comman that would allow me to reduce an image down to 400 pixel width without
          > loss of scale. I want to have a similiar command that will reduce a large
          > image down to 400 pilel height without loss of scale. I fiddled with the
          > command for width but can't get it to work for height. Can I get some help
          > rewriting the following command to work for 400 pixel height? Thanks.
          > // User Variables
          > var width = 400;
          >
          > // Command
          > var dom = fw.getDocumentDOM();
          > var scale = width/dom.width;
          > var height = dom.height * scale;
          > dom.setDocumentImageSize({left:dom.left, top:dom.top, right:dom.left+width,
          > bottom:dom.top+height}, {pixelsPerUnit:dom.resolution,
          > units:dom.resolutionUnits});
          >
          >
          • 2. Re: Help with a Command script
            Level 7
            Tom Hersh wrote:
            > Hello,
            > Awhile back someone wrote the following script for me. The idea was to make a
            > comman that would allow me to reduce an image down to 400 pixel width without
            > loss of scale. I want to have a similiar command that will reduce a large
            > image down to 400 pilel height without loss of scale. I fiddled with the
            > command for width but can't get it to work for height. Can I get some help
            > rewriting the following command to work for 400 pixel height? Thanks.
            > // User Variables
            > var width = 400;
            >
            > // Command
            > var dom = fw.getDocumentDOM();
            > var scale = width/dom.width;
            > var height = dom.height * scale;
            > dom.setDocumentImageSize({left:dom.left, top:dom.top, right:dom.left+width,
            > bottom:dom.top+height}, {pixelsPerUnit:dom.resolution,
            > units:dom.resolutionUnits});
            >
            >
            Tom,
            It was back in March and Senocular wrote the code for you.

            Maybe you can contact him through his website.

            http://tinyurl.com/rlcwl

            SKB
            • 3. Re: Help with a Command script
              Level 7
              My suggestion was coming more from the old saying "give a man a fish and
              feed him for a day ... show him how to fish ....

              alex
              • 4. Re: Help with a Command script
                Level 7
                A l e x M a r i � o wrote:
                > My suggestion was coming more from the old saying "give a man a fish and
                > feed him for a day ... show him how to fish ....
                >
                > alex

                I suppose Friday is a good day to fish. :)

                SKB
                • 5. Re: Help with a Command script
                  Tom Hersh Level 1
                  Is it necessary to do it through a batch process? If not, I still don't see how to see the script? Is there a special window. I see the two steps I made in the history but not the script behind it. Thanks.
                  • 6. Re: Help with a Command script
                    Tom Hersh Level 1
                    I want to be clearer about the latest problem. Let's say I want a command that will change an image to 400 pixels height and keep the width to scale. Now let's say I take an image and change the height to 400 pixels. And let's say this particular image now has a height of 400 pixels and a width of 500 pixels. Now I go to the history and make a command of what I have just done (which I see how to do). Now I apply the new command to another image of different dimensions than the first. What happens is that, after the command is applied, the result is an image with 400 pixels height but it will also have 500 pixels in width. It retains the 500 width for all future images, even though I want the width at scale. How do I keep the width at scale. Thanks, Tom
                    • 7. Re: Help with a Command script
                      Level 7
                      Tom Hersh wrote:
                      > I want to be clearer about the latest problem. Let's say I want a command that
                      > will change an image to 400 pixels height and keep the width to scale. Now
                      > let's say I take an image and change the height to 400 pixels. And let's say
                      > this particular image now has a height of 400 pixels and a width of 500 pixels.
                      > Now I go to the history and make a command of what I have just done (which I
                      > see how to do). Now I apply the new command to another image of different
                      > dimensions than the first. What happens is that, after the command is applied,
                      > the result is an image with 400 pixels height but it will also have 500 pixels
                      > in width. It retains the 500 width for all future images, even though I want
                      > the width at scale. How do I keep the width at scale. Thanks, Tom
                      >

                      That was the same problem as last time. The copying of history steps to
                      create the command would only work on the same size images.

                      I think if you carefully switch 'all' the 'height' and 'width' variables
                      in the original script it will work for you.

                      SKB
                      • 8. Re: Help with a Command script
                        Tom Hersh Level 1
                        I did try it that way. But I could not get it to work. The word "scale" is critical, but I switching did not help.
                        • 9. Re: Help with a Command script
                          Level 7
                          Tom Hersh wrote:
                          > I did try it that way. But I could not get it to work. The word "scale" is critical, but I switching did not help.


                          Just switch the variables word for word. Height for width and width for
                          height.

                          // User Variables
                          var width = 400;

                          // Command
                          var dom = fw.getDocumentDOM();
                          var scale = width/dom.width;
                          var height = dom.height * scale;
                          dom.setDocumentImageSize({left:dom.left, top:dom.top,
                          right:dom.left+width,
                          bottom:dom.top+height}, {pixelsPerUnit:dom.resolution,
                          units:dom.resolutionUnits});


                          // User Variables
                          var height = 400;

                          // Command
                          var dom = fw.getDocumentDOM();
                          var scale = height/dom.height;
                          var width = dom.width * scale;
                          dom.setDocumentImageSize({left:dom.left, top:dom.top,
                          right:dom.left+width,
                          bottom:dom.top+height}, {pixelsPerUnit:dom.resolution,
                          units:dom.resolutionUnits});

                          Once you see this script, it's not hard to see what it is doing.

                          This is the Fireworks generated script scaling just the height of an
                          image to 400 px from 640x480 px.

                          fw.getDocumentDOM()
                          .scaleSelection(0.83281248807907104, 0.83333333333333337,
                          "autoTrimImages transformAttributes");

                          This works on all 640x480 images. Throw in a 700x480 and it won't.

                          I'm assuming, very few people in here (myself included), would be able
                          to transform this into something that would account for varying widths
                          as senocular did.

                          SKB

                          • 10. Re: Help with a Command script
                            Tom Hersh Level 1
                            Thanks. This works fine. I thought I had tried this exact permutation without luck, but I must have missed something or other. Anyway, it's now okay. Best. Tom