3 Replies Latest reply on Aug 13, 2016 5:31 AM by pixxxel schubser

    Pixel editor script what am i getting myself into.

    PixelFixation

      Hey guys first post. I am a c# coder with zero experience in Photoshop scripting or java script. I have a Unity 2D game project that has a graphical issue that can only be solved by taking my pixel sprite sheets and adding a single pixle of padding around the out side of each sprite the same color as its neighboring pixel. So 16x16 pixel sprites become 18x18 sprites with a border that matches the next pixel in.

       

      I have been doing this manually in Photoshop cc for a while now by resizing the canvas and using the marquee tool with the move tool and coping then pasting rows of pixels. At my finest hour this takes me forty five minutes to an hour.

       

      What I want to know is what kind of undertaking it would be to automate this process with a script?

        • 1. Re: Pixel editor script what am i getting myself into.
          Chuck Uebele Adobe Community Professional & MVP

          I think that can be done with extends riptide, but it will be a bit slow - not as slow as what you're doing. Now. You would just need to create a loop that samples the pixel location you want to copy, the make a selection of the pixels you want to fill.

          • 2. Re: Pixel editor script what am i getting myself into.
            pixxxel schubser MVP & Adobe Community Professional

            Hi PixelFixation,

            I think this could do the job (for 16×16 pixel sprite):

            // border_singlePixelBorderAroundwithNeighboringPixelColor.jsx
            // erstellt einen 1 Pixel breiten umlaufenden Rand mit der Pixelfarbe des benachbarten Pixels
            // adding a single pixle of padding around the out side of each sprite the same color as its neighboring pixel.
            // 16x16 pixel sprites become 18x18 sprites with a border that matches the next pixel in
            // regards pixxxel schubser
            
            var aDoc =app.activeDocument, aSel;
            expand (1, 0, AnchorPosition.TOPRIGHT, 1, 2, 16, 0, -1, 0);
            expand (1, 0, AnchorPosition.TOPLEFT, 16, 17, 16, 0, 1, 0);
            expand (0, 1, AnchorPosition.BOTTOMCENTER, 0, 18, 2, 1, 0, -1);
            expand (0, 1, AnchorPosition.TOPCENTER, 0, 18, 16, 17, 0, 1);
            
            
            function expand (x1, y1, an, l, r, b, t, x2, y2) {
                aDoc.resizeCanvas (UnitValue((aDoc.width.as('px')+x1),"px"), UnitValue((aDoc.height.as('px')+y1),"px"), an );
                aDoc.selection.select([[l,t],[l,b],[r,b],[r,t]], SelectionType.REPLACE, 0, false);
                aSel = aDoc.selection;
                aSel.copy ();
                aDoc.paste();
                aDoc.activeLayer.translate (x2, y2);
                aDoc.activeLayer.merge();
                }
            

             

            Have fun

             

            1 person found this helpful
            • 3. Re: Pixel editor script what am i getting myself into.
              pixxxel schubser MVP & Adobe Community Professional

              Hi PixelFixation,

              you are a coder.

               

              Normally you should know: no feedback is the worst feedback.

               

              Sorry for answering your question quickly and completely.

              1 person found this helpful