I have a script on my server that dynamically creates images of chess diagrams:
<img src = "ChessImager/ChessImager.php?fen=r3k2r/1pqb2pp/pnn2p2/4p3/4Q3/NBP1B3/P4PPP/R2R2K1&square_size=45&ds_color=(143,188,143)&ls_color=(232,223,192)">
But the resulting image files are nearly 30k, too big. I want to use pngnq http://pngnq.sourceforge.net/ to shrink them. I present them in a slideshow at http://communitychessclub.com I want a new php script to create the images from ChessImager.php and pipe each of these diagram image files (~50) to a new filename like ‘game1234.png’ and I’ll batch pre-process (not real-time) them with pngnq. I have a file ‘Forsyth.csv’ which lists the data:
r1bqk2r/1p2bp1p/p2pnp2/4pN1Q/2B1P3/2N5/PP3PPP/R2R2K1|1256
r3k2r/1pqb2pp/pnn2p2/4p3/4Q3/NBP1B3/P4PPP/R2R2K1|1255
4rrk1/ppp3pp/2n4q/3p4/3P4/1NP1PpPP/PP3Q1K/R4R2|1253
rn2kb1r/1q1p2p1/p3p3/1p2N1Bp/2p1P2P/2P4Q/PP3PP1/3R1RK1|1252
I use this:
<?php $text = file('Forsyth.csv');foreach($text as $line)
{$token = explode("|", $line); print "\n"; $fen = $token[0]; $game_num = $token[1];
$phrase="games/game$game_num.php"; echo "<li> <img
src=\"ChessImager/ChessImager.php?fen=$fen&square_size=45&ds_color=(143,188,143)&ls_color=(232,223,192)\" ></li>";} ?>
Any ideas?
Update: this is posted at http://communitychessclub.com/produce.php
<?php $text = file('Forsyth.csv'); foreach($text as $line) {$token = explode("|",
$line); print "\n"; $fen = $token[0]; $game_num = $token[1]; print "\n";
$goat = "diagrams/game$game_num.png";
$src="ChessImager/ChessImager.php?fen=$fen&square_size=45&ds_color=(143,188,143)&ls_color=(232,223,192)";
echo "<li><img src = \"$src\"></li>";}
?>
Any ideas?
ChesssImager.php or one of its includes must have a
imagepng($image)line near the end that sends the generated PNG image to the web browser. If your question is how to save that data to the disk instead, you can just modify the script so that it saves the image data instead:where $filename is something unique that you can generate from the arguments passed to the script. For example:
Wherever you decide to have the script save the files, you’ll need to make sure that you (or the web server if you’re running it in a browser) has permission to write to that folder.