creating trim marks on different sized images

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
holden
Posts: 79
Joined: 2013-02-07T08:22:57-07:00
Authentication code: 6789

creating trim marks on different sized images

Post by holden »

Hey all, I need to make several templates with trim marks in the corners. I'm not sure how to do math in IM. To start I would need this:

convert -size 2400x3000 xc:white ^
-draw "line 0,0 0,100" ^
-draw "line 0,0 100,0" ^
for the first corner, then
-draw "line 2300,0 2400, 0"^
-draw "line 2400, 0 2400,100" ^
for the adjacent corner, and on and on. But, since I need to do this for different sizes, it'd be easier to have formulas in place of the coords in the -draw command. Can I pull numbers from the initial size values? I can input the different size parameters manually but I'd like the rest to be automated. Thanks
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: creating trim marks on different sized images

Post by snibgo »

I would put both lines in a single draw, and use translate, eg:

Code: Select all

convert -size 2400x3000 xc:white -draw "translate 20,20 line 0,0 0,100 line 0,0 100,0" x.png
"-draw" follows SVG rules, so "translate" comes before "line", not after.

I don't think you can use a formula inside "-draw", so you need to use environment variables.
snibgo's IM pages: im.snibgo.com
holden
Posts: 79
Joined: 2013-02-07T08:22:57-07:00
Authentication code: 6789

Re: creating trim marks on different sized images

Post by holden »

Thanks for the response, I think it may be faster for me to do this in Gimp than to figure out the code-y way :lol:
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: creating trim marks on different sized images

Post by fmw42 »

You can make a template image of one tick mark (cross?) using -draw on a transparence background (or find an appropriate symbol graphic). Then just composite it at several locations as desired. You can even read it once and use clones or mpr to composite it.

see
http://www.imagemagick.org/Usage/layers/#convert
http://www.imagemagick.org/Usage/layers/#flatten
http://www.imagemagick.org/Usage/basics/#parenthesis
http://www.imagemagick.org/Usage/basics/#clone
http://www.imagemagick.org/Usage/files/#mpr

Here is an example using the IM internal image logo:

Unix format:

convert logo: \
\( -size 100x100 xc:none -fill black -draw "line 50,0 50,100 line 0,50 100,50" -write mpr:tic +delete \) \
mpr:tic -gravity northwest -geometry +50+50 -compose over -composite \
mpr:tic -gravity northeast -geometry +50+50 -compose over -composite \
mpr:tic -gravity southeast -geometry +50+50 -compose over -composite \
mpr:tic -gravity southwest -geometry +50+50 -compose over -composite \
logo_tics.gif

Windows format:

convert logo: ^
( -size 100x100 xc:none -fill black -draw "line 50,0 50,100 line 0,50 100,50" -write mpr:tic +delete ) ^
mpr:tic -gravity northwest -geometry +50+50 -compose over -composite ^
mpr:tic -gravity northeast -geometry +50+50 -compose over -composite ^
mpr:tic -gravity southeast -geometry +50+50 -compose over -composite ^
mpr:tic -gravity southwest -geometry +50+50 -compose over -composite ^
logo_tics.gif
Post Reply