13 Replies Latest reply on Jan 10, 2012 1:28 PM by arc fixer

    How do I put a thin 1px rectangle around an image?

    omar_m Level 1

      Using Photoshop CS5, can someone tell me how I put a thin 1px rectangle around an existing image


      For example, imagine I have an image that 500px wide and 200 px high

      I want a 10px gap all around and then I want the thin rectangle


      What would the proper way of doing this?


      Importantly, the image will be a PNG, so I want the gap around the image to be transparent


      I'm planning to have on a black background, so want my rectangle to be a white line

       

      + is Photoshop the correct application to use to do this?

       

      Thanks in advance



      Omar

        • 1. Re: How do I put a thin 1px rectangle around an image?
          Curt Y Level 7

          Is this the same as a 1 pixel wide white line?

           

          Why not use a ruler and just draw it in.  If you hold shift key and click on 2 points a straight line will be drawn between them.

           

          There are probably more elegant ways, but this is quck and simple.

          • 2. Re: How do I put a thin 1px rectangle around an image?
            omar_m Level 1

            never thought of that  

            but: it does not to be precise - exactly 10px on the outer all around

             

            is there anyway of drawing a rectanle with no filling precisely?

             

            thanks

            • 3. Re: How do I put a thin 1px rectangle around an image?
              arc fixer Level 3

              Hi Omar.

               

              You can't go wrong with Kurts suggestion. But could get tedious on multiple images.

               

              There are multiple ways to accomplish this in Ps. Here is another that is suitable for automation, in case you have more than one image.

               

              1. Duplicate Layer (Ctrl+J) - Isolates image for following step.

              2. Canvas Size (Ctrl+Alt+C) : Relative, centered. W:+22, H=+22 - Creates expanded canvas.10px(gap) + 1px (stroke)= 11px, times 2 to cover the top and bottom & both sides.

              3. Delete background layer-Leaves the image over the expanded transparent canvas.

               

              The following steps apply the stroke at the perimeter.

               

              4. Select Canvas (Ctrl+A)

              5. Contract Selection: 1px

              6. Invert selection (Ctrl+Shft+I) Now you have 1 px selection at the perimeter of the image.

              7. Fill selection with white.

               

              This should leave your image, a 10px transparent gap, then a 1px white stroke on one layer. Ready to export as Png.

               

              I don't know about elegant, but this is a pretty mainstream approach that works for one image or recorded as an action.

               

              FWIW.

               

              Peace,

              Lee

              1 person found this helpful
              • 4. Re: How do I put a thin 1px rectangle around an image?
                omar_m Level 1

                thanks lee

                i had something like this in mind - but wasnt sure how best to do

                 

                i'm with u in all the steps, apart from:

                 

                5. Contract Selection: 1px

                 

                how do i do this?

                 

                i like the method - and i'll use a lot

                but it seems to be a bit of a hack   ?         

                • 5. Re: How do I put a thin 1px rectangle around an image?
                  arc fixer Level 3

                  Hi Omar.

                   

                  5. Contract Selection:  Menu>Select>Modify>Contract

                   

                  You could set this up a little more simply if all the images were the same size. But this approach will add 10px of transparency and a 1px stroke to any size image.

                   

                  I'm not smart enought to do a "hack". But I don't mind kludging. But hack, kludge, or stroke of genius, it doesn't matter. Record it as an action, set you actions to Button Mode, and one click does it. Or you can run the action on dozens of images in a batch.

                   

                  If you find a more elegant solution, get back to us.

                   

                  Peace,

                  Lee

                  • 6. Re: How do I put a thin 1px rectangle around an image?
                    omar_m Level 1

                    thanks lee

                    i love the solution

                    automation: yes your method is awesome because i can automate for ANY sized image

                     

                    small problem still though...

                    after doing ctrl a, i don't have the option to contract by 1px

                    the only option available from the menu is border

                    i'm pretty sure i've followed your instructions word for word

                     

                    let me  know if there's something obvious i might be missing

                    thanks

                    • 7. Re: How do I put a thin 1px rectangle around an image?
                      arc fixer Level 3

                      Hi Omar.

                       

                      Actually, maybe I was missing something. I don't think the Border option was available back when I made similar actions. This option will get rid of some of the kludge factor. Anyway, I'm on CS3. Both Border & Contract options are available. The Border option merges 2 steps into 1. Contract 1px & Invert Selection is replaced by Border 1px.

                       

                      New and slightly improved:

                       

                      4. Select Canvas

                      5. Menu>Select>Modify>Border: 1px.

                      6. Fill with white.

                       

                      See if that works.

                       

                      Lee

                      • 8. Re: How do I put a thin 1px rectangle around an image?
                        omar_m Level 1

                        lee: u are absolutely awesome

                        thanks a million!

                        see the pretty pictures i've now made:

                         

                        Green-Sea-Turtle.png

                         

                        Forest-Flowers.png

                        absolutely damn awesome!!!!!

                         

                         

                         

                         

                        omar

                        • 9. Re: How do I put a thin 1px rectangle around an image?
                          arc fixer Level 3

                          Hi Omar.

                           

                          Very nice results!

                           

                          Automation one of the best things Ps has going for it. Well worth spending a little time investigating its potential. Which is awesome.

                           

                          Me, not so much. But I do appreciate a pat on the head as much as the next dog.

                           

                          Glad to help.

                           

                          Peace,

                          Lee

                          • 10. Re: How do I put a thin 1px rectangle around an image?
                            omar_m Level 1

                            lee... i'm really happy with the results

                            only a small thing though: the outline sint 1px

                            i only noticed that afterwards

                             

                            se the following 2 pics below

                            the first was created using ur method

                            the second was created by a longer manual process: say we have 100 x 100 pic. create a new pic with transparent background of 122 x 122. now create a white blank pic of 120 x 120 size. copy the white and put into 122x122. no from the layers menu, add a 1px stroke. now flatten. now erase the white - u now have the required outline!. create a new pic with transparent background of size 122x122. copy and paste both th eoriginal pic and new outline pic. hey presto, 50 steps later, u have what i wanted.

                             

                            problem is it's 50 steps

                            i like ur solution. this can be automated. the second solution can't be automated: BUT it gives the 1px outline i wanted!

                             

                            let me know what u think

                             

                            thanks

                             

                            first pic:

                             

                            Garden.png

                            second pic:

                            Garden2.png

                            • 11. Re: How do I put a thin 1px rectangle around an image?
                              arc fixer Level 3

                              Hi Omar.

                               

                              Border is the problem. From the Help files:

                               

                               

                              1. For example, a border width of 20 pixels creates a new, soft-edged selection that extends 10 pixels inside the original selection border and 10 pixels outside it.

                                (Italics mine.)

                               

                              Apparently, Border is designed to remove halos. Hence the soft selection. See below. Note the row of semi transparent pixels. Oops!

                               

                              BORDER1.JPG

                               

                               

                               

                              Below is the result using my original suggestion, Contract 1px, Invert Selection, Fill. This yields a clean 1px border.

                               

                               

                              BORDER2.JPG

                               

                              Try the original recipe and see what you get.

                               

                              Lee

                              • 12. Re: How do I put a thin 1px rectangle around an image?
                                Noel Carboni Level 8

                                Here's something to get your creative thoughts flowing in possibly another direction...

                                 

                                Set the background color to the color you want for the border.  Then ensure you have a Background layer and run Image - Canvas Size, and expand the canvas by 2 pixels in each dimension, keeping the orientation selector centered.  Voila, an exact 1 pixel border of the background color.

                                 

                                There are probably other ways as well..

                                 

                                -Noel

                                • 13. Re: How do I put a thin 1px rectangle around an image?
                                  arc fixer Level 3

                                  Hi Noel.

                                   

                                  Happy New Year!

                                   

                                  Omar is looking for 10 pixels of transparency between the perimeter of the photo and the 1px border. I think. 

                                   

                                  Lee