Any tool to convert FEN strings to diagrams?

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

kinderchocolate
Posts: 454
Joined: Mon Nov 01, 2010 6:55 am
Full name: Ted Wong

Any tool to convert FEN strings to diagrams?

Post by kinderchocolate »

I have a dump of FEN positions. Does anybody know any tool to batch convert them to chess diagrams?
jpqy
Posts: 550
Joined: Thu Apr 24, 2008 9:31 am
Location: Belgium

Re: Any tool to convert FEN strings to diagrams?

Post by jpqy »

User avatar
Guenther
Posts: 4606
Joined: Wed Oct 01, 2008 6:33 am
Location: Regensburg, Germany
Full name: Guenther Simon

Re: Any tool to convert FEN strings to diagrams?

Post by Guenther »

jpqy wrote:Chess Diagram setup:

http://www.jinchess.com/chessboard/composer/

JP.
How does this batch convert multiple fens at once?
I guess it does not...

For the OP: I also did a research after I saw your post and the only
two programs I found which could do this won't work on Win7 anymore.

Guenther
User avatar
gbtami
Posts: 389
Joined: Wed Sep 26, 2012 1:29 pm
Location: Hungary

Re: Any tool to convert FEN strings to diagrams?

Post by gbtami »

kinderchocolate wrote:I have a dump of FEN positions. Does anybody know any tool to batch convert them to chess diagrams?
If you have pychess installed the following python script can convert to .png files.
---------------

Code: Select all

import os
import sys

from pychess.Savers.fen import load
from pychess.Savers.png import save


def convert(infile):
    with open(infile) as f:
        fenfile = load(f)
        for i in range(len(fenfile)):
            model = fenfile.loadToModel(i, None)
            outfile = "%s-%s.png" % (infile[:-4], i)
            with open(outfile, "w") as o:
                save(o, model)


if __name__ == "__main__":
    if len(sys.argv) > 1:
        arg = sys.argv[1]
        if arg[-4:].lower() == ".fen":
            if os.path.isfile(arg):
                convert(arg)
        elif os.path.exists(arg):
            for file in os.listdir(arg):
                if file[-4:].lower() == ".fen":
                    convert(os.path.join(arg, file))
    else:
        path = os.path.abspath(os.path.dirname(__file__))
        for file in sorted(os.listdir(path)):
            if file[-4:].lower() == ".fen":
                convert(os.path.join(path, file))
User avatar
hgm
Posts: 27796
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Any tool to convert FEN strings to diagrams?

Post by hgm »

kinderchocolate wrote:I have a dump of FEN positions. Does anybody know any tool to batch convert them to chess diagrams?
WinBoard does have a 'Save as diagram' menu option to save the current board position as a Windows .bmp file. This doesn't allow batch conversion, but it would be sort of trivial to write a loop around it so that all FENs in a position file are saved on different (say numbered) .bmp files. E.g. I could make an option that in match mode, starting from the given position file with auto-stepping, would abort each game after setting up the start position with a call to the routine that saves as diagram.

I don't know if Windows .bmp files are a format that is useful to you, however.
jwes
Posts: 778
Joined: Sat Jul 01, 2006 7:11 am

Re: Any tool to convert FEN strings to diagrams?

Post by jwes »

hgm wrote:
kinderchocolate wrote:I have a dump of FEN positions. Does anybody know any tool to batch convert them to chess diagrams?
WinBoard does have a 'Save as diagram' menu option to save the current board position as a Windows .bmp file. This doesn't allow batch conversion, but it would be sort of trivial to write a loop around it so that all FENs in a position file are saved on different (say numbered) .bmp files. E.g. I could make an option that in match mode, starting from the given position file with auto-stepping, would abort each game after setting up the start position with a call to the routine that saves as diagram.

I don't know if Windows .bmp files are a format that is useful to you, however.
There are any number of programs that will convert bmps to other formats.
User avatar
asimpereira
Posts: 38
Joined: Sun Mar 25, 2012 9:06 am

Re: Any tool to convert FEN strings to diagrams?

Post by asimpereira »

I use the Latex chessboard package to convert fens to images for my ebooks. However it's not exactly a ready made tool and you will need to set it up. If it's a one time thing, feel free to send the fens to me.
--
Regards,
Asim

For the love of the game http://mychessapps.com
Jesse Gersenson
Posts: 593
Joined: Sat Aug 20, 2011 9:43 am

Re: Any tool to convert FEN strings to diagrams?

Post by Jesse Gersenson »

kinderchocolate wrote:I have a dump of FEN positions. Does anybody know any tool to batch convert them to chess diagrams?
fen2bmp.exe

Does anyone know of a similar tool native to Linux? There is c++ source code available for fen2bmp but it includes <windows.h>, which I do not know how to convert.
User avatar
yurikvelo
Posts: 710
Joined: Sat Dec 06, 2014 1:53 pm

Re: Any tool to convert FEN strings to diagrams?

Post by yurikvelo »

kinderchocolate wrote:I have a dump of FEN positions. Does anybody know any tool to batch convert them to chess diagrams?
You can use FEN2PNG online tool like this: http://www.jinchess.com/chessboard/composer/

e.g.

2r1q3/1Q3bpk/R1nBp1pp/3pP3/2pP1NPP/2P2PK1/8/8 w - - 19 41

can be coded to URL

http://www.jinchess.com/chessboard/?p=- ... w&download

with simple script you can convert text file with FEN lines to URL (strip slashes + replace numbers with dashes)
and then batch download with wget or CURL

Code: Select all

<?php
$fens = file&#40;'fen.txt');
foreach ($fens as $key=>$fen&#41;&#123;
$fen=str_replace&#40;'/', '', $fen&#41;;
$fen=str_replace&#40;'1', '-', $fen&#41;;
$fen=str_replace&#40;'2', '--', $fen&#41;;
$fen=str_replace&#40;'3', '---', $fen&#41;;
$fen=str_replace&#40;'4', '----', $fen&#41;;
$fen=str_replace&#40;'5', '-----', $fen&#41;;
$fen=str_replace&#40;'6', '------', $fen&#41;;
$fen=str_replace&#40;'7', '-------', $fen&#41;;
$fen=str_replace&#40;'8', '--------', $fen&#41;;
$a = explode&#40;' ', $fen&#41;;
$fen=$a&#91;0&#93;;

$url="http&#58;//www.jinchess.com/chessboard/?p=".$fen."&tm=w&download";

$result = file_get_contents&#40;$url, false, $context&#41;;

file_put_contents&#40;$fen.'.png', $result&#41;;
&#125;



?>
under *nix you have to install PHP package, under Windows - download PHP Zip package and run via php-cli.exe
Jesse Gersenson
Posts: 593
Joined: Sat Aug 20, 2011 9:43 am

Re: Any tool to convert FEN strings to diagrams?

Post by Jesse Gersenson »

http://fen2eps.sourceforge.net/#contributions

compile with g++ fen2eps.cpp -o fen2eps

and run:

Code: Select all

echo 'rnbqkbnr/pp1p1p1p/6p1/2p1p3/2P1P3/6P1/PP1P1PBP/RNBQK1NR b KQkq - 1 4' | ./fen2eps > OUTPUT.eps && convert OUTPUT.eps OUTPUT.png
batch script, FENLIST is a text file listing fen's
bash one-liner:

Code: Select all

index=1;cat FENLIST | while read list; do (( index++));echo "$list"|./fen2eps > "$index".eps && convert "$index".eps "$index".png;done