5 Replies Latest reply on Nov 1, 2012 3:18 AM by c.pfaffenbichler

    auto copy one pixel row from image....

    dejansuc

      Can someone help me write a script that:

      - from my selection (1 pixel row)

      - auto copy selected area to next row into new layer (up or down)... and so on (into the same second layer)... until it reaches the end of the image

      - the result is a photos with two layers; in the first is my image and in second is multicolored pattern

       

      _1251299sol.jpg

        • 1. Re: auto copy one pixel row from image....
          c.pfaffenbichler Level 9

          You could try this, but from a certain height on simply transforming might be considerably quicker:

           

          // 2012, use it at your own risk;

          #target photoshop

          if (app.documents.length > 0) {

          var originalRulerUnits = app.preferences.rulerUnits;

          app.preferences.rulerUnits = Units.PIXELS;

          myDocument = app.activeDocument;

          // new layer;

          var id14 = charIDToTypeID( "CpTL" );

          executeAction( id14, undefined, DialogModes.NO );

          var theLayer = myDocument.activeLayer;

          var theHeight = theLayer.bounds[3]-theLayer.bounds[1];

          var theCheck = false;

          var theCounter = 1;

          // duplicate, move and merge the layer;

          while (theCheck == false) {

          if (theLayer.bounds[3] < myDocument.height) {

          var theCopy = theLayer.duplicate();

          theCopy.translate(0, theLayer.bounds[3] - theLayer.bounds[1]);

          theCounter++;

          var theLayer = theCopy.merge();

          //$.writeln(theCounter);

          }

          else {theCheck = true};

          };

          // reset;

          app.preferences.rulerUnits = originalRulerUnits;

          };

          1 person found this helpful
          • 2. Re: auto copy one pixel row from image....
            dejansuc Level 1

            Exactly what I was looking for...

             

            What should I change in this script:

            1. to copy selected line horizontaly UP

            2. to copy selected line verticaly LEFT

            3. to copy selected line verticaly RIGHT

             

             

            Thnx!!

            • 3. Re: auto copy one pixel row from image....
              c.pfaffenbichler Level 9

              To duplicate the selected part up changing the if-clause and the line that tranlate (moves) 

              if (theLayer.bounds[1] > 0) {
              var theCopy = theLayer.duplicate();
              theCopy.translate(0, theLayer.bounds[1] - theLayer.bounds[3]);
              

              should do it.

               

              For left

              if (theLayer.bounds[0] > 0) {
              var theCopy = theLayer.duplicate();
              theCopy.translate(theLayer.bounds[0] - theLayer.bounds[2], 0);
              
              • 4. Re: auto copy one pixel row from image....
                dejansuc Level 1

                hmm... not working for left...

                • 5. Re: auto copy one pixel row from image....
                  c.pfaffenbichler Level 9

                  I don’t see a problem; naturally the Selection should be a vertical column.

                  One should include a check for this condition, I guess.

                   

                  // 2012, use it at your own risk;

                  #target photoshop

                  if (app.documents.length > 0) {

                  var originalRulerUnits = app.preferences.rulerUnits;

                  app.preferences.rulerUnits = Units.PIXELS;

                  myDocument = app.activeDocument;

                  // new layer;

                  var id14 = charIDToTypeID( "CpTL" );

                  executeAction( id14, undefined, DialogModes.NO );

                  var theLayer = myDocument.activeLayer;

                  var theHeight = theLayer.bounds[3]-theLayer.bounds[1];

                  var theCheck = false;

                  var theCounter = 1;

                  // duplicate, move and merge the layer;

                  while (theCheck == false) {

                  if (theLayer.bounds[0] > 0) {

                  var theCopy = theLayer.duplicate();

                  theCopy.translate(theLayer.bounds[0] - theLayer.bounds[2], 0);

                  theCounter++;

                  var theLayer = theCopy.merge();

                  //$.writeln(theCounter);

                  }

                  else {theCheck = true};

                  };

                  // reset;

                  app.preferences.rulerUnits = originalRulerUnits;

                  };