Skip to main content

Convert a PGN into a GIF with stockfish evaluation chart

Project description

gifpgn

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

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. 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_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.1.2.tar.gz (308.8 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.1.2-py3-none-any.whl (320.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gifpgn-0.1.2.tar.gz
  • Upload date:
  • Size: 308.8 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.1.2.tar.gz
Algorithm Hash digest
SHA256 7b80ab1cd29633548ee756a05b1372218848e490827f064ecd44ecb4162fac5b
MD5 9b7be571cddf439586df8bcd45c4040f
BLAKE2b-256 fd2e4e78328a2b27b7df1734797b40fa7b80de4bc57bc9958969f00f9cd75ce5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gifpgn-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 320.8 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.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 230ccdc3cc9f2e87cd65cf9372e10b117962071877d1d04df2c997b9c84d1ce0
MD5 71a8180b67549d15c318be9e0d2e646b
BLAKE2b-256 b8184b6e877dc31d08dffc22334b8fbe50f2968b9b521a84cc212a5901fbbafb

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