filling squares on chess board

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
manit
Posts: 123
Joined: 2009-01-30T22:31:26-07:00

Re: filling squares on chess board

Post by manit »

here is my script

Code: Select all

#we will draw 50 pixel squares on a white paper 
convert -size 800x600 xc:white board.jpg

#drawing board
convert.exe board.jpg -fill white -stroke black -draw " path 'M 200,100  l 400,0 l 0,400 l -400,0 l 0,-400' " square.jpg

# draw vertical lines over previously generated
magick-convert.exe square.jpg -fill white -stroke black -draw " path 'M 250,100 l 0,400 m 50,0 l 0,-400 m 50,0 l 0,400 m 50,0 l 0,-400 m 50,0 l 0,400 m 50,0 l 0,-400 m 50,0 l 0,400 ' " vertical.jpg

#draw horizontal lines over previously generated
convert.exe vertical.jpg -fill white -stroke black -draw " path  'M 200,150 l 400,0 m 0,50 l -400,0 m  0,50 l 400,0 m 0,50 l -400,0 m 0,50 l 400,0 m 0,50 l -400,0 m 0,50 l 400,0 ' " vert-horiz.jpg
Also I wonder when I choose output file as something.svg & open it in in web browser .
It shows me the text commands not the image intended .
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: filling squares on chess board

Post by anthony »

You you need to fill in an existing image?

the "checkerboard" pattern has 15x15 pixel squares, create one the right size and enlarge.
Or even easier use "the "gray50" hash pattern (1x1 pixel hash)

Code: Select all

convert -size 8x8 pattern:gray50 -scale 5000%  chessboard.png
However the bottom right square should be white (mnemonic: white is right) so negate it (before enlarging)

Code: Select all

convert -size 8x8 pattern:gray50 -negate -scale 5000% chessboard.png
If you like other colors use +level-color
See Level Adjustment by Color
http://www.imagemagick.org/Usage/color_ ... vel-colors

Or if you want a checkerboard pattern of images, you can look at using the 'CheckerTile' virtual-pixel method to generate it...
http://www.imagemagick.org/Usage/misc/#checker_tile
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
manit
Posts: 123
Joined: 2009-01-30T22:31:26-07:00

Re: filling squares on chess board

Post by manit »

Using checkerboard pattern yielded good result .
Also I noticed that if I save images in bmp format (bulky) then colour filling using mspaint is nice except the edge of board has an inner grey edge .
See attached image.(There ain't any image uploading in posting . I have to point to temporary locations . Later , image will disapear .)
Image
Stroke width as 1 pixel did not remove that hair gray line around edge of board.
Last edited by manit on 2012-03-09T02:27:41-07:00, edited 1 time in total.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: filling squares on chess board

Post by anthony »

The images generated by my commands would be perfectly pure black and white. If you used -resize rather than -scale then you may not get a pure result.

Perhaps saving it to BMP format resulted in some image distortion. I have no idea why, I thought the format would not be 'lossy. But then I don't use that format, but then I am not a windows user either.

If you wanted a one pixel black border , add -bordercolor black -border 1 just before the save to PNG
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply