This kind of thing has been done before. I have a relatively simple script, picframe , at http://www.fmwconcepts.com/imagemagick/index.html
and
Anthony has a more exotic solution at http://www.imagemagick.org/Usage/thumbnails/#frame_edge
If these do not help, let us know.