The package sgfutils contains a few command line utilities that help working with SGF files that describe go (igo, weiqi, baduk) games. This page is about sgftopng.

See also sgf, sgfcharset, sgfcheck, sgfcmp, sgfdb, sgfdbinfo, sgfinfo, sgfmerge, sgfsplit, sgfstrip, sgftf, sgfvarsplit, sgfx, ugi2sgf.


% sgftopng [options] outfile < infile
% sgftopng [options] outfile [from]-[to] < infile
The program sgftopng creates a go diagram using convert (from ImageMagick).

The input (read from stdin) is an SGF file. The outfile parameter must be something with an extension known to convert, such as .png, .jpg, or .gif. The default is out.png.

Basic example

% cat game.sgf
EV[The Four-Game Series]
PB[Honinbo Shusaku]
PW[Gennan Inseki]
PC[Residence of Tsuji Chujiro in Tennoji, Osaka]


% sgftopng < game.sgf
This yields the image below.



A FROM-TO range option will create unnumbered stones for the stones that were still alive when move number FROM was done, and numbered stones for the moves in the range FROM-TO (inclusive). When FROM is missing, it is taken to be 1. When TO is missing, it is taken to be the final move.
% sgftopng 22-29 < game.sgf
This yields the image below.


When FROM is larger than then number of the last move, one obtains a diagram showing the final board position, with only unnumbered stones. The same result is obtained via the -nonrs (no numbers) option. E.g., the following two commands are usually equivalent

% sgftopng 1000- < game.sgf
% sgftopng -nonrs < game.sgf

The -from A option indicates that stones in the diagram must be numbered starting from A. E.g.,

% sgftopng -from 1 image4.png 22-29 < game.sgf
yields the image below.


And (in another game, selecting moves 129-158, but labeling the stones 29-58):

sgftopng -from 29 image7.png 129-158 < gamex.sgf


Part of the board

Using the VW property, an SGF file can indicate that only part of the board should be shown. It can also indicate labels for stones. For example.
% cat stelling.sgf
GN[Een stelling]

% sgftopng image5.png 1-6 < stelling.sgf
% sgftopng image6.png 7- < stelling.sgf
This yields the images below.

image5 image6


Some SGF files contain multiple games, and the -game M option selects the M-th game present. The default choice is game #1, the first in the SGF file.

Each game can contain multiple variations, and the -var N option selects variation N to be shown, where the number N can be found using the -info option described below. The default choice is variation 0 (the final one). Again the from-to option selects the range of moves to be shown as numbered moves.

The -info option lists the variations given in the input file (and does not draw a diagram).

% sgftopng -info < tesujilecture7.sgf
Game #1
var 1: (1-0 (1-1 (2-3 (4-11)
var 2:                (4-4 (5-10)
var 3:                     (5-5 (6-13)
var 4:                          (6-6)))
var 5:                (4-7))
var 6:           (2-3 (4-4 (5-6)
var 7:                     (5-7))
var 8:                (4-6)))
var 9:      (1-0 (1-2)
var 10:           (1-6)
var 11:           (1-4)
var 12:           (1-1 (2-5)
var 13:                (2-5)))
var 14:      (1-26 (27-27 (28-33 (34-37)
var 15:                          (34-37))
var 16:                   (28-28 (29-38)

The number of moves in a variation from-to is TO−FROM+1. In particular, nodes in a tree diagram with TO = FROM−1 have zero moves (and are problaby setup nodes, with AB[], AW[]).


Sometimes a discussion involves coordinates (rather than labeled points).

The -coord option asks for a border with coordinates. Columns are labeled by letters from A, omitting I. Rows by numbers from 1, counted starting at the bottom row. The coordinates are placed both left and right, top and bottom. Using -coordLB one asks to only show coordinates left and bottom (etc.), so that -coord is equivalent to -coordLRTB.

The -view option selects a viewing rectangle (that overrides any VW[] instructions found in the SGF file). The parameter is ROWMIN-ROWMAX,COLMIN-COLMAX, counting from 1, and from the top left hand corner. Selecting a view does not change the coordinates of the points shown.

The -nonrs option asks to omit move numbers. For example,

% sgftopng -nonrs -coordTR -view 1-8,15-19 -o 161.png 161.sgf
% sgftopng -nonrs -coordBL -view 1-8,15-19 -o 161a.png 161.sgf
yielded the diagrams

and .


By default Times-Roman is used. One can specify a different font, either because it looks better, or because it has characters needed, e.g. katakana in labels on Japanese diagrams. For example,
% sgftopng -font Quivira.ttf -o a.png < a.sgf

Command line length

The command lines that sgftopng produces are longer than some systems can handle. Give some limit to tell sgftopng that it should use temporary files.
% sgftopng -maxcommandsz=8000 -o a.png < a.sgf