Answers.Body: <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.sstatic.net/6TzKI.png" rel="noreferrer"><img src="https://i.sstatic.net/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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-15T15:57:31.503Z
Answers.LastActivityDate: 2020-03-15T15:57:31.503Z
Answers.UserDisplayName: SmallChess
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-15T09:30:27.397Z
Answers.Text: I don't read this as asking anybody to write code - more if there is something pre-existing already that the OP can install/download. In the Linux world there are bazillions of file format converters available for free, it's not unreasonable to ask if there's one already available.
Answers.UserDisplayName: Ian Bush
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-15T09:57:29.263Z
Answers.Text: @Jorge Acuna, I do not use Linux, but this IS simple in Windows. You can just use any ChessBase product, including the free viewer, and open the PGN file, get to the position, and go to the "Home" tab, and click "Copy Position". No code involved. Your post is also not an answer, and should have been put in the comments only.
Answers.UserDisplayName: PhishMaster
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-15T15:57:47.490Z
Answers.Text: Well, it's a simple task. I did it in like 2 hours. The problem described here is like the basics in chess programming.
Answers.UserDisplayName: SmallChess
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-17T01:55:04.950Z
Answers.Text: Well, doing it from scratch, if you can do that in 2 hours you must be gainfully employed at least. If you have systems in place already, may turn to be a rather fast feature to implement.
   The original post was not referring to a "tool and/or plugin to extend or create the feature on a Linux console", to my recollection. But, if this is the case and on Linux you do these plugins or scripts and pass them around for free, ok. Forget I mentioned anything. Linux is free for all land no? so I understand you asking for this easily coded tool, according to smartchess.
Answers.UserDisplayName: Jorge Acuna
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-15T09:11:14.260Z
Answers.LastActivityDate: 2020-03-15T09:11:14.260Z
Answers.UserDisplayName: Jorge Acuna
Answers.Body: <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.sstatic.net/YTucDm.png" rel="noreferrer"><img src="https://i.sstatic.net/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.sstatic.net/pOZrAm.png" rel="noreferrer"><img src="https://i.sstatic.net/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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-15T16:37:30.630Z
Answers.LastActivityDate: 2020-03-15T16:37:30.630Z
Answers.LastEditDate: 2020-06-17T09:59:59.497Z
Answers.UserDisplayName: Ellie
Body: <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>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-03-15T08:08:42.813Z
Comments.Text: Not quite sure what you mean by "render" but if you just mean read the file and show the game scid <filename> or xboard <filename> will do it - once you have installed the appropriate one
Comments.UserDisplayName: Ian Bush
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-03-15T08:25:49.467Z
Comments.Text: I updated the question.
Comments.UserDisplayName: wintermeyer
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-03-15T08:55:03.577Z
Comments.Text: Probably simplest is to open the pgn with your favourite pgn reader and get a screenshot - https://itsfoss.com/take-screenshot-linux/ I know of no dedicated tool to do all this in one step, I'll leave the answers for someone that does
Comments.UserDisplayName: Ian Bush
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-03-15T15:58:23.040Z
Comments.Text: PGNs are for storing entire games, so do you want to save an image of the game after the last move? or at a given move? Otherwise, what you probably want to work with are FENs, which is a standard notation for describing a particular position not game.
Comments.UserDisplayName: Ellie
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-03-15T16:28:49.040Z
Comments.Text: Hi. I see your edits. Yes it's simple but you still need something like Python package to parse PGN into FENs. PGN by itself is a game, so no unix tool can convert it to an image.
Comments.UserDisplayName: SmallChess
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-03-16T07:25:06.607Z
Comments.Text: This sounds like a question for [Software REcommendations]*https://softwarerecs.stackexchange.com/)
Comments.UserDisplayName: Mawg
Tags: <engines><software><pgn><chessboards>
Title: Render a chessboard from a PGN file
ThreadText: # Render a chessboard from a PGN file
  
  (Asked by: username_0 on 2020-03-15)
  
  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.
  
  **Tags:** engines, software, pgn, chessboards
  
  > **Comments:**
  > **username_1**: Not quite sure what you mean by "render" but if you just mean read the file and show the game scid <filename> or xboard <filename> will do it - once you have installed the appropriate one  
  > **username_0**: I updated the question.  
  > **username_1**: Probably simplest is to open the pgn with your favourite pgn reader and get a screenshot - https://itsfoss.com/take-screenshot-linux/ I know of no dedicated tool to do all this in one step, I'll leave the answers for someone that does  
  > **username_2**: PGNs are for storing entire games, so do you want to save an image of the game after the last move? or at a given move? Otherwise, what you probably want to work with are FENs, which is a standard notation for describing a particular position not game.  
  > **username_3**: Hi. I see your edits. Yes it's simple but you still need something like Python package to parse PGN into FENs. PGN by itself is a game, so no unix tool can convert it to an image.  
  > **username_4**: This sounds like a question for [Software REcommendations]*https://softwarerecs.stackexchange.com/)  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_2 on 2020-03-15. Score: 23 | Accepted answer
  
  You can use the [SVG rendering functionalities](https://python-chess.readthedocs.io/en/latest/svg.html) of [python-chess](https://python-chess.readthedocs.io/en/latest/). 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](https://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation) 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)*:
  
  [![enter image description here](https://i.sstatic.net/YTucDm.png)](https://i.sstatic.net/YTucDm.png)
  
  ## 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](https://www.chessgames.com/perl/chessgame?gid=1333302): `adams_kasparov_2005.pgn`
  * `python boardtosvg.py 'adams_kasparov_2005.pgn'`
  
  Saved file:
  
  [![enter image description here](https://i.sstatic.net/pOZrAm.png)](https://i.sstatic.net/pOZrAm.png)
  
  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](https://stackoverflow.com/q/6589358/4511762)
  
  
  ---
  
  ### Answer by username_3 on 2020-03-15. Score: 8
  
  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:
  
  [![enter image description here](https://i.sstatic.net/6TzKI.png)](https://i.sstatic.net/6TzKI.png)
  
  General steps:
  
  * Parse your PGN file with Python python-chess. Very easy, trust me.
  * Use your parsed FENs. Follow the workflow above.
  
  
  ---
  
  ### Answer by username_5 on 2020-03-15. Score: 1
  
  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.
  
  > **Comments:**
  > **username_1**: I don't read this as asking anybody to write code - more if there is something pre-existing already that the OP can install/download. In the Linux world there are bazillions of file format converters available for free, it's not unreasonable to ask if there's one already available.  
  > **username_6**: @username_5, I do not use Linux, but this IS simple in Windows. You can just use any ChessBase product, including the free viewer, and open the PGN file, get to the position, and go to the "Home" tab, and click "Copy Position". No code involved. Your post is also not an answer, and should have been put in the comments only.  
  > **username_3**: Well, it's a simple task. I did it in like 2 hours. The problem described here is like the basics in chess programming.  
  > **username_5**: Well, doing it from scratch, if you can do that in 2 hours you must be gainfully employed at least. If you have systems in place already, may turn to be a rather fast feature to implement.  The original post was not referring to a "tool and/or plugin to extend or create the feature on a Linux console", to my recollection. But, if this is the case and on Linux you do these plugins or scripts and pass them around for free, ok. Forget I mentioned anything. Linux is free for all land no? so I understand you asking for this easily coded tool, according to smartchess.  
  
  ---
  
  