-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ add coordinates to ImagineOutput (#40)
- Loading branch information
Showing
8 changed files
with
132 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
* text=auto | ||
|
||
/docs export-ignore | ||
/benchmarks export-ignore | ||
/tests export-ignore | ||
/.gitattributes export-ignore | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
*.cache | ||
composer.lock | ||
resources/ | ||
vendor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/sh | ||
|
||
dir=../resources/ | ||
|
||
mkdir -p $dir | ||
|
||
curl https://source.winehq.org/git/wine.git/blob/HEAD:/fonts/tahoma.ttf -o $dir/font.ttf | ||
curl https://upload.wikimedia.org/wikipedia/commons/thumb/f/f0/Chess_kdt45.svg/1920px-Chess_kdt45.svg.png -o $dir/bk.png | ||
curl https://upload.wikimedia.org/wikipedia/commons/thumb/4/47/Chess_qdt45.svg/1024px-Chess_qdt45.svg.png -o $dir/bq.png | ||
curl https://upload.wikimedia.org/wikipedia/commons/thumb/f/ff/Chess_rdt45.svg/1024px-Chess_rdt45.svg.png -o $dir/br.png | ||
curl https://upload.wikimedia.org/wikipedia/commons/thumb/9/98/Chess_bdt45.svg/1024px-Chess_bdt45.svg.png -o $dir/bb.png | ||
curl https://upload.wikimedia.org/wikipedia/commons/thumb/e/ef/Chess_ndt45.svg/1024px-Chess_ndt45.svg.png -o $dir/bn.png | ||
curl https://upload.wikimedia.org/wikipedia/commons/thumb/c/c7/Chess_pdt45.svg/1024px-Chess_pdt45.svg.png -o $dir/bp.png | ||
curl https://upload.wikimedia.org/wikipedia/commons/thumb/4/42/Chess_klt45.svg/1024px-Chess_klt45.svg.png -o $dir/wk.png | ||
curl https://upload.wikimedia.org/wikipedia/commons/thumb/1/15/Chess_qlt45.svg/1024px-Chess_qlt45.svg.png -o $dir/wq.png | ||
curl https://upload.wikimedia.org/wikipedia/commons/thumb/7/72/Chess_rlt45.svg/1024px-Chess_rlt45.svg.png -o $dir/wr.png | ||
curl https://upload.wikimedia.org/wikipedia/commons/thumb/b/b1/Chess_blt45.svg/1024px-Chess_blt45.svg.png -o $dir/wb.png | ||
curl https://upload.wikimedia.org/wikipedia/commons/thumb/7/70/Chess_nlt45.svg/1024px-Chess_nlt45.svg.png -o $dir/wn.png | ||
curl https://upload.wikimedia.org/wikipedia/commons/thumb/4/45/Chess_plt45.svg/1024px-Chess_plt45.svg.png -o $dir/wp.png | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Output with Imagine | ||
|
||
This option requires [Imagine library](https://packagist.org/packages/imagine/imagine) | ||
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 me 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](https://commons.wikimedia.org/wiki/Category:SVG_chess_pieces). | ||
|
||
```php | ||
<?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); | ||
``` | ||
|
||
<img src="https://user-images.githubusercontent.com/179866/112304837-411be280-8c9e-11eb-8333-c2489f9bef05.png"> | ||
|
||
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 | ||
<?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); | ||
``` | ||
|
||
<img src="https://user-images.githubusercontent.com/179866/113125801-4685a980-9217-11eb-9e0a-0acf54c4ea88.png"> | ||
|
||
A complete list of arguments: | ||
|
||
```php | ||
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 an utility script, named [get-resources.sh](get-resources.sh), that downloads | ||
all pieces images from Wikimedia, plus a free font to use. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters