sgfutils

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

% 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
(;
FF[4]
EV[The Four-Game Series]
RO[2]
PB[Honinbo Shusaku]
BR[4d]
PW[Gennan Inseki]
WR[8d]
KM[0]
RE[Unfinished]
DT[1846-07-28]
PC[Residence of Tsuji Chujiro in Tennoji, Osaka]

;B[qd];W[dc];B[pq];W[oc];B[cp];W[eq];B[po];W[jq];B[ce];W[qf]
;B[pf];W[pg];B[of];W[qc];B[qe];W[rc];B[qg];W[ed];B[cm];W[df]
;B[cg];W[oq];B[op];W[nq];B[pr];W[np];B[ql];W[on];B[pm];W[jd]
;B[dg];W[eg];B[eh];W[fh];B[ei];W[fi];B[ej];W[fj];B[fk];W[ef]
;B[gk];W[eo];B[lc];W[jc];B[le];W[dm];B[dn];W[cf];B[bf];W[ek]
;B[em];W[dl];B[en];W[dh];B[ci];W[bg];B[ch];W[be];B[dq])

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

image1

Numbering

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.

image2

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.

image4

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

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

image7

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
(;GM[1]FF[4]
SZ[19]VW[an:ms]
GN[Een stelling]
PC[Amsterdam]
DT[1976-11-19]
C[http://www.win.tue.nl/~aeb/games/stelling3.png]PL[B]
AB[ds][dr][er][es][fq][gq][hq][iq][jr][kr][js][ks]
AW[cs][cr][cq][dq][eq][ep][fp][go][hp][ip][jp][jq][kq][lq][lr][ls];
B[gs];W[fr];B[is];W[gr];B[hr];W[fs];B[er];W[hs];B[es];W[ir];B[gs];
LB[jr:a])

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

image5 image6

Variations

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[]).

Coordinates

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 .

Font

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