0

I am creating this image:

enter image description here

using this command:

convert -size 720x480 xc:black -strokewidth 5 -stroke lime -draw "line 105,400 205,400" -stroke blue -draw "line 105,405 205,405" -stroke blue -strokewidth 2 -draw "rectangle 140,150 260,230 " -draw "rectangle 320,150 440,230 " -draw "rectangle 500,150 620,230 " -draw "rectangle 140,300 260,380 " -draw "rectangle 320,300 440,380 " -draw "rectangle 500,300 620,380 " test.png

but my image shall look like this:

enter image description here

each rectangle shall have a width of 180px and a height of 120px, and the green/blue line shall have a width of 170px and a height of 10px how do I specify this?

I tried rostok's suggestion and it created me this image, which is not 100% correct: enter image description here

utdev
  • 3,942
  • 8
  • 40
  • 70

1 Answers1

1

Try this:

magick convert \
-size 720x480 xc:black \
-strokewidth 4 \
-stroke lime \
-draw "line 103,467 273,467" \
-stroke #0030ff \
-draw "line 103,471 273,471" \
-strokewidth 9 \
-draw "path 'M 108,159 h 171 v 111 h -171 v -115 Z'" \
-draw "path 'M 290,159 h 171 v 111 h -171 v -115 Z'" \
-draw "path 'M 472,159 h 171 v 111 h -171 v -115 Z'" \
-draw "path 'M 108,288 h 171 v 111 h -171 v -115 Z'" \
-draw "path 'M 290,288 h 171 v 111 h -171 v -115 Z'" \
-draw "path 'M 472,288 h 171 v 111 h -171 v -115 Z'" \
output.png 

Your rects have different stroke width in horizontal and vertical sides however I assumed you wanted same stroke everywhere.

rostok
  • 2,057
  • 2
  • 18
  • 20
  • It is not working a 100% I posted the image which your command does create you may have a look at it. – utdev Sep 20 '16 at 07:41
  • This is really strange. I tried this code with: Linux, ImageMagick 6.3.7 11/17/10 Q16, Win ImageMagick 6.7.9-8 2012-09-22 Q8 and even Win ImageMagick 7.0.2-5 Q16 x64 and all worked good. What version are you using? – rostok Sep 20 '16 at 12:07
  • @rostock I am using version: ImageMagick 7.0.2-0 Q16 x64 2016-06-12 – utdev Sep 20 '16 at 12:44
  • yep it's really strange it draws all lines correctly, apart from the bottom lines – utdev Sep 20 '16 at 12:55
  • Update IM. I tried with your version and can confirm it isn't working properly. – rostok Sep 20 '16 at 15:13
  • @rostock did you find another hint yet :) – utdev Sep 21 '16 at 13:30
  • My only suggestion is to update IM to latest stable version or revert to v6. – rostok Sep 21 '16 at 13:35
  • Ok after downgrading my version to 6.9.3-7 it did worked thanks alot – utdev Oct 28 '16 at 13:17
  • I have just one more question could you explain what each "coordinate" does (whre it belongs to) – utdev Oct 28 '16 at 13:29
  • Full specs are here: https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths. Note that upper and lowercase letters do matter as they can be absolute position coordinates (upper) or relative (lower). Obviously I chose lower for most cases in order to cut and paste remaining lines. – rostok Oct 28 '16 at 13:41
  • do you know a way to make it fully transparent (instead of the black background) I did this xc:transparent and the black background inside of the rectangles are still blacks where as the rest is transparent – utdev Oct 28 '16 at 14:29
  • add '-fill none' before first draw path – rostok Oct 28 '16 at 14:57
  • is it possible to calculate how big the area shall be inside of the rectangle for instance 220x145 px ? – utdev Nov 02 '16 at 10:58
  • Your question is quite vague. Could you elaborate? – rostok Nov 02 '16 at 18:35
  • Basically I want the areas which the rectangles surround (black area inside of the rectangles) have a size of 220x145px, how do I have to change the command if I want to achieve this? – utdev Nov 03 '16 at 08:28
  • Thus is there a way to center this? – utdev Nov 03 '16 at 10:06
  • You should read the specs at mozilla's site. Regardless, the path syntax is quite obvious. For example in `-draw "path 'M 472,288 h 171 v 111 h -171 v -115 Z'"` M sets the starting point, h draws line horizontally, v vertically. Adjust accordingly if you want to have rectangle with different dimensions. – rostok Nov 03 '16 at 15:46
  • Thanks I understood everything except for that last -115 Z, so far as I understand it goes back to the starting point but why do you have that value -115? The docs stated out this **The path will move to point (10,10) and then move horizontally 80 points to the right, then 80 points down, then 80 points to the left, and then back to the start.** – utdev Nov 03 '16 at 16:15
  • The extra 4 pixels are to make sure rect is fully rectangular. Without it starting corner would be chipped. Probably there are some other, better ways to draw such rectangles. I wanted to cut&paste as much as possible and minimize need to enter different parameters. – rostok Nov 03 '16 at 16:28