Skip to main content
Participating Frequently
January 10, 2012
Answered

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

  • January 10, 2012
  • 3 replies
  • 28724 views

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

    This topic has been closed for replies.
    Correct answer arc_fixer

    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


    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

    3 replies

    Noel Carboni
    Legend
    January 10, 2012

    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

    arc_fixer
    Participating Frequently
    January 10, 2012

    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

    arc_fixer
    Participating Frequently
    January 10, 2012

    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

    omar_m1Author
    Participating Frequently
    January 10, 2012

    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   ?         

    arc_fixer
    Participating Frequently
    January 10, 2012

    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

    January 10, 2012

    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.

    omar_m1Author
    Participating Frequently
    January 10, 2012

    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