chess_gif package

Submodules

chess_gif.create_frame module

class chess_gif.create_frame.ChessImage(colors: tuple, side: int = 70, piece_theme: str = 'merida', h_margin: int = 0, v_margin: int = 0)

Bases: object

Creates Single Image frames for rendering the GIFs as per requirements.

Parameters:
  • colors (tuple) – Specify white and black square color in the format (white_color ,black_color).

  • side (int, optional) – Side of single square of the chess_board in pixels. Defaults to 70.

  • piece_theme (str, optional.) – Choose one of the available piece-themes mentioned in the notes below. Defaults to merida.

  • h_margin (int, optional) – Black horizontal margin around the chess_board to be rendered in the GIF. Default 0.

  • v_margin (int, optional) – Black vertical margin around the chess_board to be rendered in the GIF. Default 0.

create_board_image(board: Board) Image

Renders board on to the base chess image.

create_initial_board() Image

Returns a PIL image object of the base chess board without pieces.

side

side of one square on the chessboard in pixels

class chess_gif.create_frame.PieceImages

Bases: object

Class to help load PieceImages

static get_piece_image_dict(piece_theme: str, size: int = 70)

chess_gif.download_data module

chess_gif.gif_maker module

class chess_gif.gif_maker.GIFMaker(**kwargs: dict)

Bases: object

Class for converting a chess PGN file to a GIF.

Parameters:

pgn_file_path (str) – Path to the source PGN file to be convereted to GIF.

Other Parameters:
  • colors (tuple, optional) – colors for white and black squares.. Default `` (‘#dee3e6’,’#8ca2ad’) ``.

  • piece_theme (str, optional) – Choose one of the available piece_themes. Default merida.

  • side (int, optional) – Size of the side of a single chess-square in pixels. Default 70.

  • h_margin (int, optional) – Black horizontal margin around the chess_board to be rendered in the GIF. Default 0.

  • v_margin (int, optional) – Black vertical margin around the chess_board to be rendered in the GIF. Default 0.

  • delay (float, optional) – Delay in milliseconds betweeen individual moves. Default 1000.

Example

>>> from chess_gif.gif_maker import Gifmaker
>>> obj = Gifmaker('game.pgn')
>>> obj.make_gif('chess_game.gif)
chess_game.gif will be created in the current working directory.
_images/chess_game.gif

The resolution of the images is adjustable by changing the side keyword argument.

Note

Following are the available piece-themes:

{ ‘alpha’, ‘california’ , ‘cardinal’ , ‘cburnett’ , ‘chess7’ , ‘chessnut’ , ‘companion’ , ‘dubrovny’ , ‘fantasy’ , ‘fresca’ , ‘gioco’ , ‘icpieces’ , ‘kosal’ , ‘leipzig’ , ‘letter’ , ‘libra’ , ‘maestro’ , ‘merida’ , ‘mono’ , ‘pirouetti’ , ‘pixel’ , ‘reillycraig’ , ‘riohacha’ , ‘shapes’ , ‘spatial’ , ‘staunty’ , ‘tatiana’ }.

These are the publicly available themes taken from lichess.org’s amazing repository-lila .

make_gif_from_pgn_file(pgn_file_path: str, gif_file_path: str = 'chess.gif')

Makes gif for the loaded pgn at the specified destination file path.

Parameters:
  • pgn_file_path (str) – A pgn file containing chess game

  • gif_file_path (str) – Destination directory to store the gif file.

make_gif_from_pgn_string(pgn_string: str, gif_file_path: str = 'chess.gif')

Makes gif for the loaded pgn at the specified destination file path.

Parameters:
  • pgn_string (string) – A valid pgn string

  • gif_file_path (str) – Destination directory to store the gif file.

Module contents