user21799: I’d like to render a 2D chessboard image and save it after the last move as a PNG or JPEG from a given PGN file on a Linux console. How can I do this?
I have a PGN file and I want to get a screenshot of the board.
Seems to be a simple task but I can’t find a solution for it which is scriptable on the Linux console.
P.S. The wording "simple task" seems to be annoying for some readers here. Being not a native speaker I have a hard time to understand this nuance but I by no mean want to step on anybody's feet. Coming from a Linux console background I have the feeling that this should be doable on the console with ease. But that I haven't found the tool to do it.

user21801: I don't think calling it a "simple task" in order for someone to give you the code for free is very polite imo.
On top of that, is surely doable, but its not a simple task. It requires implementing a class to handle the graphic representation, and another class to do the "translation". Also there are quite a couple of factors to take into consideration. If you don't have the knowledge to even start to do it, you should hire someone to do it for you then. Afaik, this forum is for helping coders who are actually doing the work, and are stuck in a specific part of their project; its not a codewish fountain for everyone to ask for free implementations.

user825: Yes, of course it's possible. I've done it a lot professionally. However, there is no tool that just takes a PGN chess game and convert it into images. You will need to do some programming, not very hard.
Here is a link on how one can generate machine learning data set on chess. You should be able to reuse the code. I highlighted the part that will relate to your problem.
https://github.com/Elucidation/tensorflow_chessbot has an example:
 
General steps:

Parse your PGN file with Python python-chess. Very easy, trust me.
Use your parsed FENs. Follow the workflow above.


user3594: You can use the SVG rendering functionalities of python-chess. This will allow you to create a SVG-formatted visualisation of any board position loaded using python-chess.
FEN to SVG
For example, given a FEN as input (say we save our python script as boardtosvg.py)
Using python3 and the python-chess library version 0.30.1
import chess
import chess.svg
import sys

arguments = sys.argv
fen = str(arguments[1])

board = chess.Board(fen)
boardsvg = chess.svg.board(board=board)
f = open("BoardVisualisedFromFEN.SVG", "w")
f.write(boardsvg)
f.close()


Example, FEN: 'rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1'

Command to run your script from the terminal:
python boardtosvg.py 'rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1'


Saved file (in case you cannot open SVGs, you can at least use a browser such as chrome to view the file):

Position from a PGN to SVG
Similarly, if the input is a PGN file, then here's how you'd for istance save the SVG of the last position of the game (you can extend this to saving the position at any move):
import chess
import chess.svg
import chess.pgn
import sys

arguments = sys.argv
pgnfilename = str(arguments[1])

#Read pgn file:
with open(pgnfilename) as f:
    game = chess.pgn.read_game(f)
#Go to the end of the game and create a chess.Board() from it:
game = game.end()
board = game.board()
boardsvg = chess.svg.board(board=board)
f = open("BoardVisualisedFromPGN.SVG", "w")
f.write(boardsvg)
f.close()


Example, PGN of Adams vs Kasparov 2005: adams_kasparov_2005.pgn
python boardtosvg.py 'adams_kasparov_2005.pgn'

Saved file:

Now all that is left to do is to convert the so-created SVG files to PNG, which you can also do in python, see the solutions in the link below:

Convert SVG to PNG in Python


21799: <p>I’d like to render a 2D chessboard image and save it after the last move as a PNG or JPEG from a given PGN file on a Linux console. How can I do this?</p>

<p>I have a PGN file and I want to get a screenshot of the board.</p>

<p>Seems to be a simple task but I can’t find a solution for it which is scriptable on the Linux console.</p>

<p>P.S. The wording "simple task" seems to be annoying for some readers here. Being not a native speaker I have a hard time to understand this nuance but I by no mean want to step on anybody's feet. Coming from a Linux console background I have the feeling that this should be doable on the console with ease. But that I haven't found the tool to do it.</p>
 21801: <p>I don't think calling it a "simple task" in order for someone to give you the code for free is very polite imo.</p>

<p>On top of that, is surely doable, but its not a simple task. It requires implementing a class to handle the graphic representation, and another class to do the "translation". Also there are quite a couple of factors to take into consideration. If you don't have the knowledge to even start to do it, you should hire someone to do it for you then. Afaik, this forum is for helping coders who are actually doing the work, and are stuck in a specific part of their project; its not a codewish fountain for everyone to ask for free implementations.</p>
 825: <p>Yes, of course it's possible. I've done it a lot professionally. However, there is no tool that just takes a PGN chess game and convert it into images. You will need to do some programming, not very hard.</p>

<p>Here is a link on how one can generate machine learning data set on chess. You should be able to reuse the code. I highlighted the part that will relate to your problem.</p>

<p><a href="https://github.com/Elucidation/tensorflow_chessbot" rel="noreferrer">https://github.com/Elucidation/tensorflow_chessbot</a> has an example:</p>

<p><a href="https://i.stack.imgur.com/6TzKI.png" rel="noreferrer"><img src="https://i.stack.imgur.com/6TzKI.png" alt="enter image description here"></a> </p>

<p>General steps:</p>

<ul>
<li>Parse your PGN file with Python python-chess. Very easy, trust me.</li>
<li>Use your parsed FENs. Follow the workflow above.</li>
</ul>
 3594: <p>You can use the <a href="https://python-chess.readthedocs.io/en/latest/svg.html" rel="noreferrer">SVG rendering functionalities</a> of <a href="https://python-chess.readthedocs.io/en/latest/" rel="noreferrer">python-chess</a>. This will allow you to create a SVG-formatted visualisation of any board position loaded using python-chess.</p>
<h2>FEN to SVG</h2>
<p>For example, given a <a href="https://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation" rel="noreferrer">FEN</a> as input (say we save our python script as <code>boardtosvg.py</code>)</p>
<p><em>Using python3 and the python-chess library version <code>0.30.1</code></em></p>
<pre><code>import chess
import chess.svg
import sys

arguments = sys.argv
fen = str(arguments[1])

board = chess.Board(fen)
boardsvg = chess.svg.board(board=board)
f = open(&quot;BoardVisualisedFromFEN.SVG&quot;, &quot;w&quot;)
f.write(boardsvg)
f.close()
</code></pre>
<ul>
<li><p>Example, FEN: <code>'rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1'</code></p>
</li>
<li><p>Command to run your script from the terminal:</p>
<p><code>python boardtosvg.py 'rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1'</code></p>
</li>
</ul>
<p>Saved file <em>(in case you cannot open SVGs, you can at least use a browser such as chrome to view the file)</em>:</p>
<p><a href="https://i.stack.imgur.com/YTucDm.png" rel="noreferrer"><img src="https://i.stack.imgur.com/YTucDm.png" alt="enter image description here" /></a></p>
<h2>Position from a PGN to SVG</h2>
<p>Similarly, if the input is a PGN file, then here's how you'd for istance save the SVG of the last position of the game (you can extend this to saving the position at any move):</p>
<pre><code>import chess
import chess.svg
import chess.pgn
import sys

arguments = sys.argv
pgnfilename = str(arguments[1])

#Read pgn file:
with open(pgnfilename) as f:
    game = chess.pgn.read_game(f)
#Go to the end of the game and create a chess.Board() from it:
game = game.end()
board = game.board()
boardsvg = chess.svg.board(board=board)
f = open(&quot;BoardVisualisedFromPGN.SVG&quot;, &quot;w&quot;)
f.write(boardsvg)
f.close()
</code></pre>
<ul>
<li>Example, PGN of <a href="https://www.chessgames.com/perl/chessgame?gid=1333302" rel="noreferrer">Adams vs Kasparov 2005</a>: <code>adams_kasparov_2005.pgn</code></li>
<li><code>python boardtosvg.py 'adams_kasparov_2005.pgn'</code></li>
</ul>
<p>Saved file:</p>
<p><a href="https://i.stack.imgur.com/pOZrAm.png" rel="noreferrer"><img src="https://i.stack.imgur.com/pOZrAm.png" alt="enter image description here" /></a></p>
<p>Now all that is left to do is to convert the so-created SVG files to PNG, which you can also do in python, see the solutions in the link below:</p>
<ul>
<li><a href="https://stackoverflow.com/q/6589358/4511762">Convert SVG to PNG in Python</a></li>
</ul>
