Any tool to convert FEN strings to diagrams?
Moderators: hgm, Rebel, chrisw
-
- Posts: 454
- Joined: Mon Nov 01, 2010 6:55 am
- Full name: Ted Wong
Any tool to convert FEN strings to diagrams?
I have a dump of FEN positions. Does anybody know any tool to batch convert them to chess diagrams?
-
- Posts: 550
- Joined: Thu Apr 24, 2008 9:31 am
- Location: Belgium
-
- Posts: 4611
- Joined: Wed Oct 01, 2008 6:33 am
- Location: Regensburg, Germany
- Full name: Guenther Simon
Re: Any tool to convert FEN strings to diagrams?
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
-
- Posts: 389
- Joined: Wed Sep 26, 2012 1:29 pm
- Location: Hungary
Re: Any tool to convert FEN strings to diagrams?
If you have pychess installed the following python script can convert to .png files.kinderchocolate wrote:I have a dump of FEN positions. Does anybody know any tool to batch convert them to chess diagrams?
---------------
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))
-
- Posts: 27822
- Joined: Fri Mar 10, 2006 10:06 am
- Location: Amsterdam
- Full name: H G Muller
Re: Any tool to convert FEN strings to 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.kinderchocolate wrote:I have a dump of FEN positions. Does anybody know any tool to batch convert them to chess diagrams?
I don't know if Windows .bmp files are a format that is useful to you, however.
-
- Posts: 778
- Joined: Sat Jul 01, 2006 7:11 am
Re: Any tool to convert FEN strings to diagrams?
There are any number of programs that will convert bmps to other formats.hgm wrote: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.kinderchocolate wrote:I have a dump of FEN positions. Does anybody know any tool to batch convert them to chess diagrams?
I don't know if Windows .bmp files are a format that is useful to you, however.
-
- Posts: 38
- Joined: Sun Mar 25, 2012 9:06 am
Re: Any tool to convert FEN strings to diagrams?
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.
-
- Posts: 593
- Joined: Sat Aug 20, 2011 9:43 am
Re: Any tool to convert FEN strings to diagrams?
fen2bmp.exekinderchocolate wrote:I have a dump of FEN positions. Does anybody know any tool to batch convert them to chess diagrams?
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.
-
- Posts: 710
- Joined: Sat Dec 06, 2014 1:53 pm
Re: Any tool to convert FEN strings to diagrams?
You can use FEN2PNG online tool like this: http://www.jinchess.com/chessboard/composer/kinderchocolate wrote:I have a dump of FEN positions. Does anybody know any tool to batch convert them to chess diagrams?
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('fen.txt');
foreach ($fens as $key=>$fen){
$fen=str_replace('/', '', $fen);
$fen=str_replace('1', '-', $fen);
$fen=str_replace('2', '--', $fen);
$fen=str_replace('3', '---', $fen);
$fen=str_replace('4', '----', $fen);
$fen=str_replace('5', '-----', $fen);
$fen=str_replace('6', '------', $fen);
$fen=str_replace('7', '-------', $fen);
$fen=str_replace('8', '--------', $fen);
$a = explode(' ', $fen);
$fen=$a[0];
$url="http://www.jinchess.com/chessboard/?p=".$fen."&tm=w&download";
$result = file_get_contents($url, false, $context);
file_put_contents($fen.'.png', $result);
}
?>
-
- Posts: 593
- Joined: Sat Aug 20, 2011 9:43 am
Re: Any tool to convert FEN strings to diagrams?
http://fen2eps.sourceforge.net/#contributions
compile with g++ fen2eps.cpp -o fen2eps
and run:
batch script, FENLIST is a text file listing fen's
bash one-liner:
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
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