Page 1 of 1

What is the best way to create dashed borders?

Posted: 2007-02-01T09:43:46-07:00
by tdan
Goal: Draw a dashed border around an existing photo with known dimensions.
Problem: My method creates a dashed border which is too thin. It does not appear like a border.
Progress:
- I drew a transparent border around the image because I did not want the border drawn on the image itself.
I wanted it to act like a border or frame, hugging the image.
- I used 4 draw commands so that the pathlines were straight and would not 'jump' between edges (try it with 1 path command).


For testing try this:

Code: Select all

convert rose: -resize 300x200! –background none –border 20 –bordercolor none
-strokewidth 20 –stroke blue –fill none
-draw “stroke-dasharray 20 20 path ‘M 0,0 h 300”
-draw “stroke-dasharray 20 20 path ‘M 300,0 v 200’”
-draw “stroke-dasharray 20 20 path ‘M 300, 200 h -300’”
-draw “stroke-dasharray 20 20 path ‘M 0, 200 h -200’”

If you try this from the command line, you will see the dashed line really is not 20px wide (at least on my monitor).
Instead, it appears offset from the image ~9 pixels or so.
Why?
Is this an issue with SVG having different resolution than IM's native resolution?

Posted: 2007-02-01T13:12:15-07:00
by tdan
Simple solution -
path defines the centerline of the stroke.
I was defining the path too far away from the image.
That's rather intuitive - somehow I missed it.

The correct drawing should be:

Code: Select all

convert rose: -resize 300x200! –background none –border 20 –bordercolor none
-strokewidth 20 –stroke blue –fill none
-draw “stroke-dasharray 20 20 path 'M 10,10 h 330' ”
-draw “stroke-dasharray 20 20 path 'M 330,10 v 230' ”
-draw “stroke-dasharray 20 20 path 'M 330, 230 h -300' ”
-draw “stroke-dasharray 20 20 path 'M 10, 230 h -200' ”

Posted: 2007-02-01T23:18:38-07:00
by anthony
WARNING: you are using word meta characters in your commands which look correct by IM will not understand. EG double quotes and dashes are not what they seem!

Posted: 2007-02-02T13:59:46-07:00
by tdan
You are right - the code doesn't work if you copy it as is.

How do I make sure the characters are what they should be?
I'm not quite sure what a meta character is. . . is there an extra bit which modifies the character for certain programs?

Re: What is the best way to create dashed borders?

Posted: 2007-02-04T07:21:52-07:00
by anthony
Replace them with the right ones and DO NOT use word to edit text files used for code.

Under linux I use charcater translations...
For example... fix quotes and dashes....

Code: Select all

tr '\021\022\023\024' \'\'\"\" <file_in |\
  tr '\221\222\223\224\226\227\213' \'\'\"\"-  > file_out
Note I do this a lot for english text stories I download, and quotes stuff up many other programs, even though they look fine on most browser setups.