'.PHP_EOL; print '

Error '.$code.'


'.PHP_EOL; print '

'.htmlspecialchars($message).'

'.PHP_EOL; exit(); } if (!isset($_GET['path'])) fail(500, "no request"); $query = $_GET['path']; $parts = explode('/', $query); if (count($parts) != 3) fail(404, "Not found"); $mode_string = $parts[0]; $card_string = $parts[1]; $symbols = strlen($card_string); if ($symbols < 3 || $symbols > 30 || ($symbols % 3) != 0) fail(401, "Not a valid card string"); $cards = array(); for ($i = 0; $i < $symbols; $i += 3) { $card = substr($card_string, $i, 2); $face = substr($card_string, $i+2, 1); if ($face == ' ') { $flip = false; } else if ($face == '-') { $flip = true; } else { fail(401, 'Invalid orientation: '.$face); } $assetfile = realpath(dirname(__FILE__).'/assets/'.$card.'.png'); if (!file_exists($assetfile)) fail(401, "Not a valid card: ".$card); $cards[] = array('file' => $assetfile, 'flipped' => $flip); } //print_r($cards); $card_base_w = 564; $card_base_h = 970; $dw = $card_base_w / 4; $dh = $card_base_h / 4; $pad = 20; if ($mode_string === "planetary") { if ($symbols != 24) fail(401, "Incorrect number of cards dealt"); header("Content-type: image/png"); $width = 5 * $pad + 4 * $dw; $height = 5 * $pad + 4 * $dh; $image = imagecreatetruecolor($width, $height); imagealphablending($image, false); $transparent = imagecolorallocatealpha($image, 255, 255, 255, 127); imagefilledrectangle($image, 0, 0, $width, $height, $transparent); imagealphablending($image, true); $xs = array(1.5, 1, 0, 1, 1.5, 2, 3, 2); $ys = array(3, 2, 1.5, 1, 0, 1, 1.5, 2); for ($i = 0; $i < 8; $i++) { $cardimage = imagecreatefrompng($cards[$i]['file']); if ($cards[$i]['flipped']) { $flippedimage = imagecreatetruecolor($card_base_w, $card_base_h); imagealphablending($flippedimage, false); imagefilledrectangle($flippedimage, 0, 0, $card_base_w, $card_base_h, $transparent); imagealphablending($flippedimage, true); imagecopyresampled($flippedimage, $cardimage, 0, 0, $card_base_w - 1, $card_base_h - 1, $card_base_w, $card_base_h, -$card_base_w, -$card_base_h); imagecopyresampled($image, $flippedimage, $xs[$i] * ($dw + $pad) + $pad, $ys[$i] * ($dh + $pad) + $pad, 0, 0, $dw, $dh, $card_base_w, $card_base_h); imagedestroy($flippedimage); //imagecopyresampled($image, $cardimage, $xs[$i] * ($dw + $pad) + $pad, $ys[$i] * ($dh + $pad) + $pad, $card_base_w-1, $card_base_h-1, $dw, $dh, -$card_base_w, -$card_base_h); //imagecopyresampled($image, $cardimage, ($xs[$i] + 1) * ($dw + $pad), ($ys[$i] + 1) * ($dh + $pad), 0, 0, -$dw, -$dh, $card_base_w, $card_base_h); } else { imagecopyresampled($image, $cardimage, $xs[$i] * ($dw + $pad) + $pad, $ys[$i] * ($dh + $pad) + $pad, 0, 0, $dw, $dh, $card_base_w, $card_base_h); } imagealphablending($image,true); imagedestroy($cardimage); } imagealphablending($image,false); imagesavealpha($image,true); imagepng($image); imagedestroy($image); } else fail(404, "Not found"); //print "hi!
".PHP_EOL; //print "get: ". $_GET['path']; //fail(200, "done"); ?>