Generate
Main class used to generate a GIF. See readme for usage.
- class gifpgn.gifpgn.CreateGifFromPGN(game: Game)[source]
Bases:
object- Parameters:
game (chess.pgn.Game) – An instance of
chess.pgn.Gamefrom the python-chess library.
- add_analysis_bar(width: int = 30) None[source]
Adds an analysis bar to the right side of the chess board.
Note
Requires that a PGN has been loaded with
[%eval ...]annotations for each half move.Alternatively the PGN can be decorated using the
gifpgn.utils.PGNclass.- Parameters:
width (int) – Width of the analysis bar in pixels, defaults to 30
- Raises:
MissingAnalysisError – At least one ply in the PGN has a missing
[%eval ...]annotation
- add_analysis_graph(height: int = 81) None[source]
Adds an analysis graph to the bottom of the chess board.
Note
Requires that a PGN has been loaded with
[%eval ...]annotations for each half move.Alternatively the PGN can be decorated using the
gifpgn.utils.PGNclass.- Parameters:
height (int) – Height of the analysis graph in pixels, defaults to 81
- Raises:
MissingAnalysisError – At least one ply in the PGN has a missing
[%eval ...]annotation
- add_headers(height: int = 20) None[source]
Adds headers with player names, captured pieces, and clock (if PGN contains
[%clk ...]annotations) to the top and bottom of the chess board.- Parameters:
height (int) – Height of headers in pixels, defaults to 20
- property board_size: int
int: Size of the board in pixels, defaults to 480
Note
Size will be rounded down to the nearest multiple of 8
- enable_nags()[source]
Enable numerical annoation glyphs
Note
Requires that a PGN has been loaded with
[%eval ...]annotations for each half move.Alternatively the PGN can be decorated using the
gifpgn.utils.PGNclass.- Raises:
MissingAnalysisError – At least one ply in the PGN has a missing
[%eval ...]annotation
- property frame_duration: float
float: Duration of each frame in seconds, defaults to 0.5
- generate(output_file: str | None = None) BytesIO | None[source]
Generate the GIF and either save it to the specified file path or return the raw bytes if no file path is specified.
game = chess.pgn.read_game(io.StringIO(pgn_string)) gif = CreateGifFromPGN(game) gif.generate("/path/to/output.gif")
- Parameters:
output_file (Optional[str]) – Filepath to save to, defaults to None
- Return Optional[BytesIO]:
Raw bytes of the generated GIF if
output_fileparameter is set, else returnsNone
- property max_eval: int
int: Maximum evaluation displayed on analysis graph or bar in centipawns, defaults to 1000
- property square_colors: Dict[bool, str]
Dict[chess.Color, str]: A dict mapping each chess.Color to a color format understandable by PIL