http://www.gnu.org/copyleft/gpl.html * * The chess pieces come from occ-1.2.4, which in turn took * them from -> http://www.tommasovitale.it/my/wcg */ $theme="wcg"; include "images/$theme/board.php"; function image_resize($image, $x, $y) { $cx = imagesx($image); $cy = imagesy($image); $img = imagecreatetruecolor($x, $y); imagecopyresized($img, $image, 0,0,0,0, $x, $y, $cx, $cy); return($img); } function getSquareSizedImage($URL) { global $PSIZE; $img = imagecreatefromstring(file_get_contents($URL)); return image_resize($img, $PSIZE, $PSIZE); } function blankBoard() { global $theme, $BSIZE, $PSIZE; $bsq = getSquareSizedImage("images/$theme/b_square.jpg"); $wsq = getSquareSizedImage("images/$theme/w_square.jpg"); $board = imagecreatetruecolor ($BSIZE, $BSIZE); for($x = 0; $x < 8 ; $x++) for($y = 0; $y < 8 ; $y++) { $odd = ($x + $y) %2; $sq = $wsq ; if ($odd) $sq = $bsq; imagecopymerge($board, $sq, $PSIZE * $x, $PSIZE * $y, 0, 0, $PSIZE, $PSIZE, 100); } imagedestroy($bsq); imagedestroy($wsq); return $board; } function posx($pos) { $x = $pos{0}; if ("A" == $x || "a" == $x) return 0; if ("B" == $x || "b" == $x) return 1; if ("C" == $x || "c" == $x) return 2; if ("D" == $x || "d" == $x) return 3; if ("E" == $x || "e" == $x) return 4; if ("F" == $x || "f" == $x) return 5; if ("G" == $x || "g" == $x) return 6; if ("H" == $x || "h" == $x) return 7; return $x; } function posy($pos) { $y = 8 - $pos{1}; return $y; } function getPiecesFiles() { global $theme; $p["WR"]= "images/$theme/wrook.gif"; $p["WN"]= "images/$theme/wknight.gif"; $p["WB"]= "images/$theme/wbishop.gif"; $p["WQ"]= "images/$theme/wqueen.gif"; $p["WK"]= "images/$theme/wking.gif"; $p["WP"]= "images/$theme/wpawn.gif"; $p["BR"]= "images/$theme/brook.gif"; $p["BN"]= "images/$theme/bknight.gif"; $p["BB"]= "images/$theme/bbishop.gif"; $p["BQ"]= "images/$theme/bqueen.gif"; $p["BK"]= "images/$theme/bking.gif"; $p["BP"]= "images/$theme/bpawn.gif"; $p["SWR"]= "images/$theme/swrook.gif"; $p["SWN"]= "images/$theme/swknight.gif"; $p["SWB"]= "images/$theme/swbishop.gif"; $p["SWQ"]= "images/$theme/swqueen.gif"; $p["SWK"]= "images/$theme/swking.gif"; $p["SWP"]= "images/$theme/swpawn.gif"; $p["SBR"]= "images/$theme/sbrook.gif"; $p["SBN"]= "images/$theme/sbknight.gif"; $p["SBB"]= "images/$theme/sbbishop.gif"; $p["SBQ"]= "images/$theme/sbqueen.gif"; $p["SBK"]= "images/$theme/sbking.gif"; $p["SBP"]= "images/$theme/sbpawn.gif"; return $p; } function sqColor($pos) { $x = posx($pos); $y = posy($pos); $odd = ($x + $y) %2; $sq = "W" ; if ($odd) $sq = "B"; return $sq; } function getPiece($piece, $pos) { global $PIECES_IMAGES, $PIECES_FILES, $PIECES; $img = $PIECES[$piece]; if ($img) return $img; $img = imagecreatefromstring(file_get_contents($PIECES_FILES[$piece])); $PIECES[$piece] = $img; return $img; } function destroyPieces() { global $PIECES_IMAGES; foreach($PIECES_IMAGES as $img) imagedestroy($img); } function renderboard($layout) { global $theme, $BSIZE, $PSIZE, $PIECES_FILES, $PIECES; ; $board = blankBoard(); $PIECES_FILES = getPiecesFiles(); foreach($layout as $pos => $piece) if ($PIECES_FILES[$piece]) { $img = getPiece($piece, $pos); $x = posx($pos); $y = posy($pos); $w = imagesx($img); $h = imagesy($img); imagealphablending($img, false); imagealphablending($board, false); imagecopyresized($board, $img, $x * $PSIZE, $y * $PSIZE, 0, 0, $PSIZE, $PSIZE, $w, $h); } $imageType = "gif"; header("Content-type: image/$imageType"); // ready to go, no errors. $output = "image$imageType"; $output($board); // destroy last to decrease latency (in theory, although clearing // memory could prevent early swapping. imagedestroy($board); destroyPieces(); } //$BSIZE=600; $PSIZE=36; $BSIZE=36*8; $layout = $_REQUEST; if ($_REQUEST["BSIZE"]) { $BSIZE = $_REQUEST["BSIZE"]; $PSIZE = floor($BSIZE / 8); } renderboard($layout); ?>