Giter Club home page Giter Club logo

pgn-to-gif's Introduction

pgn-to-gif

Generate GIFs of chess games from PGN files.

Installation

pip3 install pgn-to-gif

Usage

usage: pgn-to-gif [-h] --pgn-path PGN_PATH --gif-path GIF_PATH [--add-initial-position {1,t,true,0,f,false}] [--highlight-last-move {1,t,true,0,f,false}] [--orientation {white,black}]
              [--size SIZE] [--coordinates {1,t,true,0,f,false}] [--css-path CSS_PATH] [--loop LOOP] [--duration DURATION] [--fps FPS] [--palettesize PALETTESIZE]
              [--subrectangles {1,t,true,0,f,false}] [--processes PROCESSES]

optional arguments:
  -h, --help            show this help message and exit
  --pgn-path PGN_PATH   path to pgn file to read (default: None)
  --gif-path GIF_PATH   path to gif file to save (default: None)
  --add-initial-position {1,t,true,0,f,false}
                        add initial position to gif (default: true)
  --highlight-last-move {1,t,true,0,f,false}
                        highlight last move on board (default: true)
  --orientation {white,black}
                        orientation of board (default: white)
  --size SIZE           size of board (default: 400)
  --coordinates {1,t,true,0,f,false}
                        add board coordinates (default: true)
  --css-path CSS_PATH   path to css file to style board (default: None)
  --loop LOOP           number of loops for gif, 0 means infinite (default: 0)
  --duration DURATION   duration of each frame (in seconds) in gif (default: 1.0)
  --fps FPS             frame per second of gif (default: 1.0)
  --palettesize PALETTESIZE
                        number of colors to quantize images to (default: 64)
  --subrectangles {1,t,true,0,f,false}
                        optimize gif by storing change (default: true)
  --processes PROCESSES
                        number of processes when converting svgs to pngs (default: 1)

Examples

Please see examples folder.

pgn-to-gif's People

Contributors

afozk95 avatar

Stargazers

 avatar  avatar

Watchers

 avatar

pgn-to-gif's Issues

Generate gif in parallel

Currently it can take some time to generate the GIF, especially if board size is big and/or game is long. Generating the board images in parallel can speed things up. This must be an option.

parameter : add-initial-position false, result not expected

pgn file

[FEN "1Q6/8/8/8/8/2K5/8/k7 w - - 0 1"]

1. Qb2# 1-0

executed command
pgn-to-gif --orientation black --duration 3.0 --add-initial-position false --loop 0 --pgn-path description_mate_in_chess_match.pgn --gif-path pgn_to_gif.gif --coordinates true --highlight-last-move true --fps 1.0

result not expected
not produce gif animation, only show 1 image
image

expected result
the queen initial position should be in Qb8 then gif animated Qb2

thanks and best regards

no library called "cairo" was found

$ uname -a
Darwin sugizo.local 16.7.0 Darwin Kernel Version 16.7.0: Sun Jun  2 20:26:31 PDT 2019; root:xnu-3789.73.50~1/RELEASE_X86_64 x86_64

$ python -V
Python 3.9.13

$ pip install -U pgn-to-gif
Collecting pgn-to-gif
  Using cached pgn_to_gif-0.0.3-py3-none-any.whl (6.7 kB)
Requirement already satisfied: python-chess in ./test0/lib/python3.9/site-packages (from pgn-to-gif) (1.999)
Requirement already satisfied: imageio in ./test0/lib/python3.9/site-packages (from pgn-to-gif) (2.25.0)
Collecting cairosvg
  Using cached CairoSVG-2.6.0-py3-none-any.whl (43 kB)
Requirement already satisfied: tinycss2 in ./test0/lib/python3.9/site-packages (from cairosvg->pgn-to-gif) (1.2.1)
Collecting cairocffi
  Using cached cairocffi-1.4.0.tar.gz (69 kB)
  Preparing metadata (setup.py) ... done
Requirement already satisfied: defusedxml in ./test0/lib/python3.9/site-packages (from cairosvg->pgn-to-gif) (0.7.1)
Requirement already satisfied: cssselect2 in ./test0/lib/python3.9/site-packages (from cairosvg->pgn-to-gif) (0.7.0)
Requirement already satisfied: pillow in ./test0/lib/python3.9/site-packages (from cairosvg->pgn-to-gif) (9.4.0)
Requirement already satisfied: numpy in ./test0/lib/python3.9/site-packages (from imageio->pgn-to-gif) (1.24.2)
Requirement already satisfied: chess<2,>=1 in ./test0/lib/python3.9/site-packages (from python-chess->pgn-to-gif) (1.9.4)
Collecting cffi>=1.1.0
  Using cached cffi-1.15.1-cp39-cp39-macosx_10_9_x86_64.whl (179 kB)
Requirement already satisfied: webencodings in ./test0/lib/python3.9/site-packages (from cssselect2->cairosvg->pgn-to-gif) (0.5.1)
Requirement already satisfied: pycparser in ./test0/lib/python3.9/site-packages (from cffi>=1.1.0->cairocffi->cairosvg->pgn-to-gif) (2.21)
Building wheels for collected packages: cairocffi
  Building wheel for cairocffi (setup.py) ... done
  Created wheel for cairocffi: filename=cairocffi-1.4.0-py3-none-any.whl size=88774 sha256=ca8922ab21abca37d891e05bf66fbd2ca5dd48d71106e53b4aad9c4932f93f77
  Stored in directory: /Users/sugizo/Library/Caches/pip/wheels/2a/f8/2e/1ba974e3c465ce58d97d09238f159afa8a36bc284bfc380241
Successfully built cairocffi
Installing collected packages: cffi, cairocffi, cairosvg, pgn-to-gif
Successfully installed cairocffi-1.4.0 cairosvg-2.6.0 cffi-1.15.1 pgn-to-gif-0.0.3

$ pgn-to-gif --pgn-path pgn_to_gif.pgn --gif-path pgn_to_gif.gif
Traceback (most recent call last):
  File "/Users/sugizo/Downloads/test0/bin/pgn-to-gif", line 5, in <module>
    from pgn_to_gif.cli import main
  File "/Users/sugizo/Downloads/test0/lib/python3.9/site-packages/pgn_to_gif/cli.py", line 4, in <module>
    from .utils import read_css, read_pgn, pgn_to_gif
  File "/Users/sugizo/Downloads/test0/lib/python3.9/site-packages/pgn_to_gif/utils.py", line 6, in <module>
    import cairosvg
  File "/Users/sugizo/Downloads/test0/lib/python3.9/site-packages/cairosvg/__init__.py", line 26, in <module>
    from . import surface  # noqa isort:skip
  File "/Users/sugizo/Downloads/test0/lib/python3.9/site-packages/cairosvg/surface.py", line 9, in <module>
    import cairocffi as cairo
  File "/Users/sugizo/Downloads/test0/lib/python3.9/site-packages/cairocffi/__init__.py", line 48, in <module>
    cairo = dlopen(
  File "/Users/sugizo/Downloads/test0/lib/python3.9/site-packages/cairocffi/__init__.py", line 45, in dlopen
    raise OSError(error_message)  # pragma: no cover
OSError: no library called "cairo-2" was found
no library called "cairo" was found
no library called "libcairo-2" was found
cannot load library 'libcairo.so.2': dlopen(libcairo.so.2, 2): image not found
cannot load library 'libcairo.2.dylib': dlopen(libcairo.2.dylib, 2): image not found
cannot load library 'libcairo-2.dll': dlopen(libcairo-2.dll, 2): image not found

please support unicode character

[Event "Budapest"]
[Site "Budapest"]
[Date "1911.??.??"]
[White "Lasker, Emanuel"]
[Black "Breyer, Gyula"]
[Result "0-1"]
[ECO "C21"]

1. e4 e5 2. d4 exd4 3. c3 d5 4. exd5 ♕xd5 5. cxd4 ♘f6 6. ♘f3 ♗b4+ 7. ♘c3 O-O 8. ♗e2 ♘e4 9. ♗d2 ♗xc3 10. bxc3 ♘c6 11. O-O ♕a5 12. ♕c2 ♗f5 13. ♗d3 ♖fe8 14. ♗e1 ♕d5 15. c4 ♕d6 16. d5 ♘e5 17. ♗xe4 ♘xf3+ 18. gxf3 ♕g6+ 19. ♔h1 ♖xe4 20. ♕c3 ♖h4 21. ♖g1 ♖xh2+ 22. ♔xh2 ♕h5+ 23. ♔g3 ♕g5+ 24. ♔h2 ♕h4+ 25. ♔g2 ♕h3# 0-1

the chess pieces in unicode character, it's not work e.g. ♕, ♗

result
only pawn move on pgn above is created

expected result
all pieces can work with unicode character

thanks n best regards

Adding pgn headers to gif option

Currently PGN headers are not used in the generated GIF in any way. Several ways of incorporating pgn headers into the GIF:

  1. Add frames with info from pgn headers before and after game.
  2. Add info from pgn headers to board frames (top of the board?)

Either way, this must be optional and pgn headers to use must be configurable.

Create more examples

Create more examples with different parameters passed and put them into the examples folder.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.