Commit 2c67f5cb authored by Peter Billam's avatar Peter Billam

1.3 now works also on a t.fen file

parent 56423634
......@@ -5,20 +5,20 @@
-- This script is free software; you can redistribute it and/or --
-- modify it under the same terms as Lua5 itself. --
---------------------------------------------------------------------
local Version = '1.2 for Lua5'
local VersionDate = '27jun2018';
local Version = '1.3 for Lua5'
local VersionDate = '28jun2018';
local Synopsis = [[
fen2img [-w 350] \
'rnb1k1nr/pppp1ppp/8/4p3/3b3q/4PPP1/PPP2K1P/RNBQ1BNR b KQkq - 0 5' \
output.png
# default width is 400 pixels
# default width is 500 pixels
# output file can be a .jpg or .png or .eps
perldoc fen2img # read the manual :-)
]]
local FEN = require 'chess.fen'
Width = 400;
Width = 500;
Flip = 'false'
local function which(s)
......@@ -61,6 +61,13 @@ Dx = round(Width * 0.1)
Fenstr = arg[iarg]
if not Fenstr then die('must specify FEN string') end
-- if Fenstr ends in .fen and exists as a file then it should be read as a file
if string.match(Fenstr, '%.fen$') then
local fenfh = assert(io.open(Fenstr, 'r'))
Fenstr = string.gsub(fenfh:read('a'), '%s+$', '')
io.close(fenfh)
end
Output = arg[iarg+1]
if not Output then die('must specify output file') end
-- 20180627 must be able to pipe into display, so if no output file
......@@ -406,7 +413,7 @@ fen2img - Creates a .png or .jpg diagram of a chess position in FEN
fen2img -w 500 "$FEN" /tmp/t.png
fen2img -w 500 "$FEN" /tmp/t.eps
fen2img -w 500 "$FEN" - | display - # pipes into display as a .png
fen2img -w 500 "$FEN" -f - | display - # flip the display
fen2img -f -w 500 "$FEN" - | display - # flip the display
=head1 DESCRIPTION
......@@ -425,10 +432,11 @@ to convert into C<.jpg> or C<.png> format.
The board will be displayed B<F>lipped, ie: from Black's point of view.
=item I<-w 500>
=item I<-w 700>
This option sets the B<W>idth in pixels of the C<.jpg> or C<.png> image,
or the width in points of C<.eps> files.
The default width is 500.
=item I<-v>
......@@ -463,6 +471,7 @@ which you move into C</usr/share/fonts/truetype/>
=head1 CHANGES
20180628 1.3 now works also on a t.fen file
20180627 1.2 introduce the -f Flip option
20180627 1.1 allows output on stdout, for piping into display
20180411 1.0 first working version
......
......@@ -43,17 +43,17 @@ CONTENT="PostScript, chess, FEN, pgn, jpg">
<H3 id="SYNOPSIS">SYNOPSIS</H3>
<pre><code> fen2img -w 500 \
<pre><code> fen2img -w 800 \
'rnb1k1nr/pppp1ppp/8/4p3/3b3q/4PPP1/PPP2K1P/RNBQ1BNR b KQkq - 0 5' \
/tmp/hammerschlag.png
display /tmp/hammerschlag.png
FEN=`pgn2fen '1.f3 e5 2. Kf2 Bc5+ 3.d4 Qh4+ 4. g3 Bxd4+ 5.e3'`
fen2img -w 500 "$FEN" /tmp/t.jpg
fen2img -w 500 "$FEN" /tmp/t.png
fen2img -w 500 "$FEN" /tmp/t.eps
fen2img -w 500 "$FEN" - | display - # pipes a .png into display
fen2img -w 500 "$FEN" -f - | display - # flip the display</code></pre>
fen2img "$FEN" /tmp/t.jpg
fen2img "$FEN" /tmp/t.png
fen2img "$FEN" /tmp/t.eps
fen2img -w 800 "$FEN" - | display - # pipes a .png into display
fen2img -f -w 800 "$FEN" - | display - # flip the display</code></pre>
<H3 id="DESCRIPTION">DESCRIPTION</H3>
......@@ -74,10 +74,11 @@ to convert into <code>.jpg</code> or <code>.png</code> format.</p>
ie: from Black's point of view.</p>
</dd>
<dt id="w-500"><i>-w 500</i></dt> <dd>
<dt id="w-700"><i>-w 700</i></dt> <dd>
<p>This option sets the <b>W</b>idth in pixels of the <code>.jpg</code>
or <code>.png</code> image, or the width in points of <code>.eps</code>
files.</p>
files.
The default width is 500</p>
</dd>
<dt id="v"><i>-v</i></dt> <dd>
......@@ -105,7 +106,8 @@ It also needs a particular TrueType font:</p>
</p>
<H3 id="CHANGES">CHANGES</H3>
<PRE> 20180627 1.2 introduce the -f Flip option
<PRE> 20180628 1.3 now works also on a t.fen file
20180627 1.2 introduce the -f Flip option
20180627 1.1 allows output on stdout, for piping into display
20180411 1.0 first working version
</PRE>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment