Re: How to detect the borders and to draw an additional border ?
Personally, I think the best way to add a border to an image is by increasing the canvas size. Rename the Background layer and duplicate it. With the duplicate selected, go to Image>Canvas Size. In the window that opens, change the units to 'Pixels" and enter the width and height you want to increase the canvas (border size). 'Relative' should be checked and the 'Anchor' should be in the center. Notice that the canvas color is grayed out; that's good because you want the increased area to be transparent. Now click the OK button and you'll have a transparent border. Add a new empty layer under your border layer and fill it with any color, design, pattern, or what ever you want for your border. Note: If you don't rename the Background layer, the canvas color option will not be grayed out (you may want that) but the border will go on the Background layer. Experiment a little to see which method you prefer.
Hope this is helpful.