Draw multiple rectangles with single command

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
Wanderer
Posts: 12
Joined: 2014-05-04T14:45:11-07:00
Authentication code: 6789

Draw multiple rectangles with single command

Post by Wanderer »

hi ,

I want to draw multiple colored rectangle in my image using the -draw command. I can use the below command to draw one rectangle/command. Is there any way possible to draw more than one rectangle in single command.

Code: Select all

convert Image1.jpg -fill black -draw "rectangle 135,55 155,60" Image2.jpg
I am on Windows using ImageMagick-6.8.9-Q16.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Draw multiple rectangles with single command

Post by snibgo »

Code: Select all

convert Image1.jpg -fill black -draw "rectangle 135,55 155,60 rectangle 235,155 255,160 rectangle 335,255 355,260 rectangle 435,355 455,360" Image2.jpg
Etc.
If you have a huge number of rectangles, you can put them in a file, eg rect.txt ...

Code: Select all

rectangle 135,55 155,60
rectangle 235,155 255,160
rectangle 335,255 355,260
rectangle 435,355 455,360
... and run the command:

Code: Select all

convert Image1.jpg -fill black -draw @rect.txt Image3.jpg
But I suggest you don't use jpeg format for solid colours like this. Png is usually more suitable.
snibgo's IM pages: im.snibgo.com
Wanderer
Posts: 12
Joined: 2014-05-04T14:45:11-07:00
Authentication code: 6789

Re: Draw multiple rectangles with single command

Post by Wanderer »

Thanks snibgo
Post Reply