Giter Club home page Giter Club logo

lila-gif's Introduction

lila-gif

Test

Webservice to render Gifs of chess positions and games, and stream them frame by frame.

Example: DrDrunkenstein vs. Zhigalko_Sergei

size render time frames colors width height
336 KiB ~60 ms 93 63 720 px 840 px

Usage

lila-gif

USAGE:
    lila-gif [OPTIONS]

OPTIONS:
        --bind <BIND>    Listen on this address [default: 127.0.0.1:6175]
    -h, --help           Print help information

HTTP API

GET /image.gif

curl http://localhost:6175/image.gif?fen=4k3/6KP/8/8/8/8/7p/8 --output image.gif
name type default description
fen ascii starting position FEN of the position. Board part is sufficient.
white utf-8 none Name of the white player. Known chess titles are highlighted. Limited to 100 bytes.
black utf-8 none Name of the black player. Known chess titles are highlighted. Limited to 100 bytes.
comment utf-8 https://github.com/lichess-org/lila-gif Comment to be added to GIF meta data. Limited to 255 bytes.
lastMove ascii none Last move in UCI notation (like e2e4).
check ascii none Square of king in check (like e1).
orientation white Pass black to flip the board.
theme brown Board theme. blue, brown, green, ic, pink, or purple.
piece cburnett Piece set from this list.

POST /game.gif

{
  "white": "Molinari", // optional
  "black": "Bordais", // optional
  "comment": "https://www.chessgames.com/perl/chessgame?gid=1251038", // optional
  "orientation": "white", // default
  "theme": "brown", // default
  "piece": "cburnett", // default
  "delay": 50, // default frame delay in centiseconds
  "frames": [
    // [...]
    {
      "fen": "r1bqkb1r/pp1ppppp/5n2/2p5/2P1P3/2Nn2P1/PP1PNP1P/R1BQKB1R w KQkq - 1 6",
      "delay": 500, // optionally overwrite default delay
      "lastMove": "b4d3", // optionally highlight last move
      "check": "e1" // optionally highlight king
    }
  ]
}

GET /example.gif

curl http://localhost:6175/example.gif --output example.gif

Render an example game.

Technique

Instead of rendering vector graphics at runtime, all pieces are prerendered on every possible background. This allows preparing a minimal color palette ahead of time. (Pieces are not just black and white, but need other colors for anti-aliasing on the different background colors).

Sprite

All thats left to do at runtime, is copying sprites and Gif encoding. More than 95% of the rendering time is spent in LZW compression.

For animated games, frames only contain the changed squares on transparent background. The example below is the last frame of the animation.

Example frame

License

lila-gif is licensed under the GNU Affero General Public License, version 3 or any later version, at your option.

The generated images include text in Noto Sans (Apache License 2.0) and a piece set by Colin M.L. Burnett (GFDL or BSD or GPL).

lila-gif's People

Contributors

brollin avatar cymruu avatar ddugovic avatar dependabot-preview[bot] avatar dependabot[bot] avatar dignissimus avatar niklasf avatar ornicar avatar srimethan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lila-gif's Issues

Add Clock Time stamps to gifs

Lichess gifs are a great way to show games, but having a clock time stamp can be helpful to provide more insights into the game, for example, if the player lost on time, or they blundered a piece because of time pressure.

Arrows support

support for green/yellow/blue arrows, want it for showing last move/explain positions

Add a frame at the end showing the result for the GIF generation

The GIF endpoint could also contain a field for the game result. In PGN it's usually included in the Header or at the very end, like "{ Black wins on time. } 0-1"

This could then be shown on a final frame, as the viewer currently can only guess the result, especially if won on time. This would also remove the need to show the last frame longer manually.

In case the field in the endpoint is not set, the GIF can just be generated like it currently is.

Showing blunders

Optional (by additional argument) showing good moves, mistakes and blunders when computer analisys is available as Lichess does (exclamation mark, question mark, etc).

Inconsistent speed in rapid

First of all, thanks for your contribution to lichess, and I love the use of Rust.

I just played a fun attacking game as white that I wanted to share to my all my friends, but most of the opening moves, and also towards the end, is played back way too fast to follow. It could seem like you use some kind of algorithm that utilizes the entire game length as a variable – and thus could create funky results with fast/premoves in longer time controls (this was rapid 10+0). I will go read the source now.

TLDR: Fast/pre-moves in rapid games are replayed way too fast in GIF

Support For 3D chess images and Gifs

I was seeing an update on coming for different pieces and board colours, was wondering if adding 3D sprites to generate chess images and gifs can be possible. Note just suggesting an idea, if it is possible it would make lichess gifs even better, but also practical for sharing the games in OTB POV.

Thanks

How to get black orientation?

Right now whenever I export gifs and it’s black turn it shows on white side, is there a parameter I can pass/some other automatic way to get black’s view? Because in screenshot the chess FEN do show who’s turn is it in the notation.

Should gracefully fallback when board theme is unrecognized

Currently, if you send a board theme that is unrecognized, you get an error:

http://localhost:6175/image.gif?fen=7R/8/8/8/8/8/rr6/R1BQK2B&theme=purple2

Failed to deserialize query string: unknown variant `purple2`, expected one of `blue`, `brown`, `green`, `ic`, `purple`

Lets gracefully fall back on the default board theme. I started trying to do this, but my rust knowledge is too lacking at the moment.

Bonus could be to smartly fall back. For instance, blue2 could fall back to blue.

MP4 generator/exporter for Lichess

Hello! 👋

I’m not sure if this is the best place to ask and share about this, but I decided to start working on a MP4 generator akin to this. I don’t know Rust, so I decided to just write it in C.

I feel like it’d be easier to use than the GIF exporter in Lichess, specially for longer games, because then people can just seek around the game more easily.

I have put my current code in a Gist: https://gist.github.com/zamfofex/3bb038ea2861d042a2a2db10c002b8e4 (It is released under the GPL, v2 only, to match two of its dependencies.)

There are a few missing features, most notably the ability to flip the board (see from black’s perspective) and player name labels. I can continue working on it if there is interest in using it for the purposes of Lichess, otherwise I think I’m okay with leaving it as is.

Thoughts would be appreciated!

Provide option to not render player names

When I or the other player have done something really embarrassing, yet interesting, I don't want the player names to show, just the game :)

Could you provide this option?

output gif from pgn

Now we can only output a gif from a series of fens, I think it's useful to add a function to output gif from a pgn.
Please consider it seriously. Thanks

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.