Skip to main content

Convert a PGN into a GIF with stockfish evaluation chart

Project description

gifpgn

PyPI Downloads GitHub commits since latest release (by date) Coverage Status Requirements Status

Generate a GIF of a chess game from a PGN with optional stockfish analysis chart.

Demo

Stockfish analysis and move arrows:

Board only, small:

Installation

pip install gifpgn

For stockfish analysis a local stockfish binary is required. For best performance you can compile your own with support for the fastest instruction sets available on your hardware. Alternatively you can install using your distribution's package manager.

eg. apt-get install stockfish

Usage

  1. Import the package:

from gifpgn import CreateGifFromPGN

  1. Initialise the class:

    • Using a PGN string:

    gif = CreateGifFromPGN(pgn_string)

    • Using a PGN file:

    gif = CreateGifFromPGN(path_to_pgn,pgn_file=True)

  2. Optionally enable stockfish evaluation:

gif.enable_evaluation()

Stockfish evaluation is expensive and may take a large amount of time to complete.

The default depth of 18 provides a reasonable trade-off of time versus accuracy. Reducing this number will significantly reduce processing time.

Please see the enable_evaluation documentation below for configuation options for numbers of threads and memory usage.

  1. Optionally enable move arrows:

gif.enable_arrows = True

  1. Generate the GIF:

gif.generate(output_file_path)

See reference section for optional parameters.

Reference

class  CreateGifFromPGN()

Arguments:

  • pgn str - PGN as a string or filepath. Filepath requires optional parameter pgn_file=True
  • reverse bool, optional - Whether board should be reversed. Defaults to False.
  • duration float, optional - Duration of each GIF frame in seconds. Defaults to 0.5.
  • pgn_file bool, optional - Specify whether pgn contains a pgn string [False] or filepath [True]. Defaults to False.

Properties

  • board_size int - Size of the board in pixels. Defaults to 480.
  • bar_size int - Width of the evaluation bar in pixels. Defaults to 30.
  • graph_size int - Height of the evaluation graph in pixels. Defaults to 81.
  • ws_color str - Color of the white squares. Defaults to "#f0d9b5".
  • bs_color str - Color of the black squares. Defaults to "#b58863".
  • max_eval int - Maximum position evaluation in centipawns. Defaults to 1000.
  • enable_arrows bool - Enable move arrows. Defaults to [False].

enable_evaluation

| enable_evaluation(path_to_stockfish='stockfish', depth: int = 18, threads: int = 1, memory: int = 1024)

Enable stockfish evaluation

Arguments:

  • path_to_stockfish str, optional - Path to stockfish binary. Defaults to 'stockfish'.
  • depth int, optional - Depth of stockfish evaluation. Defaults to 18.
  • threads int, optional - Number of threads to use in stockfish evaluation. Defaults to 1.
  • memory int, optional - Amount of memory to use in stockfish evaluation in Mb. Defaults to 1024.

generate

| generate(output_file: str)

Output GIF

Arguments:

  • output_file str - Full path and filename of output file

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gifpgn-0.2.0.tar.gz (311.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gifpgn-0.2.0-py3-none-any.whl (321.9 kB view details)

Uploaded Python 3

File details

Details for the file gifpgn-0.2.0.tar.gz.

File metadata

  • Download URL: gifpgn-0.2.0.tar.gz
  • Upload date:
  • Size: 311.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.6

File hashes

Hashes for gifpgn-0.2.0.tar.gz
Algorithm Hash digest
SHA256 396ed3cb8b8f8e264dd082a88a9b7fd2429062d8a0af03d90c1b93fd61a226c7
MD5 aa7bfb4ff50ce02d55d4e6ebc6ed183f
BLAKE2b-256 ec2f5b945f6331995790cb0b632946b168e1f5ec282a2fe7133ec1dce7aaeaab

See more details on using hashes here.

File details

Details for the file gifpgn-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: gifpgn-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 321.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.6

File hashes

Hashes for gifpgn-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cf34d94bf7ef8f3083b148e405e35f51b3a8f4c553c546b49d7f64ca793469f8
MD5 7f08a1c6577f011818b2307feb38cedf
BLAKE2b-256 b0fc036c36ef0f41e4702dcf98ec7595ae7d6fe262f326a2af16434197896e01

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page