chessimage
is a golang library for rendering a chess board PNG in specific state.
go run examples/starting_board.go | open -f -a /Applications/Preview.app/
Include in your go path.
go get github.com/cjsaylor/chessimage
Initialize the renderer with a FEN notation.
board, _ := chessimage.NewRendererFromFEN("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1")
Render the chess board to a png image.Image
interface.
f, _ := os.Create("board.png")
defer f.Close()
image, _ := board.Render(chessimage.Options{AssetPath: "./assets/")})
png.Encode(f, image)
You can highlight tiles of where a move started and ended.
board.SetLastMove(chessimage.LastMove{
From: chessimage.E4,
To: chessimage.E2,
})
You can highlight a tile as "checked".
board.SetCheckTile(chessimage.G1)
You can define rendering options at render time:
options := chessimage.Options{
AssetPath: "./assets/"
}
renderer.Render(options)
Specify the path of the image assets for the individual pieces. Feel free to use the assets packaged in this repo, but be aware they are under CC license.
Change the algorhythm for asset resizing. Depending on your performance requirements, you may need to use a faster (but more lossy) resizing method (like draw.NearestNeighbor
).
Square board size in pixels
Size of the pieces relative as a percentage to the game board tile size. If the game board size is 800
, each board tile would be 100
pixels wide, and the pieces would render at 80
pixels with the default ratio.
- Add support for
PGN
notation for rendering a board (similar to theFEN
notation setup now) - Add configuration support for changing board and tile highlight colors