This option requires Imagine library and one extension between GD and Imagick.
You need to provide an instance of Imagine, and a path of images for pieces.
Names of such images need to match a color/name code.
For example, a black pawn image must be named bp.png
(b for black and p for pawn), a
white queen image must be named wq.png
(w for white and q for queen).
Refer to Piece
class source code to get all abbreviations.
A good source for free images is Wikimedia.
<?php
// use...
$chess = new Chess();
$imagine = new \Imagine\Gd\Imagine(); // or \Imagine\Imagick\Imagine()
$output = new ImageOutput($imagine, '/your/path/to/images');
header('Content-Type: image/png');
echo $output->render($chess);
If you want to also display coordinates, you'll also need a font file, named font.ttf
and placed in the
same resource directory seen above.
Just pass a fourth parameter true
:
<?php
// use...
$chess = new Chess();
$imagine = new \Imagine\Gd\Imagine(); // or \Imagine\Imagick\Imagine()
$output = new ImageOutput($imagine, '/your/path/to/images', 480, true);
header('Content-Type: image/png');
echo $output->render($chess);
A complete list of arguments:
public function __construct(
AbstractImagine $imagine,
string $resourcesPath,
int $size = 400, // this MUST be divisible by 4
bool $coords = false,
string $darkSquareColor = '#8ca2ad',
string $liteSquareColor = '#dee3e6'
);
In this directory, you can find a utility script, named get-resources.sh, that downloads all pieces images from Wikimedia, plus a free font to use.