Scripts

Speelkaarten

Een simpele manier om speelkaarten te tonen. Er is een voorbeeld pagina toegevoegd.

cards.php
<?php
/***********************
Made by: Yearupie
Made on: 14 May 2010
***********************/

$soorten = array(
	1 => '&spades;',# Schoppen
	2 => '&clubs;', # Klaveren
	3 => '&hearts;',# Harten
	4 => '&diams;');# Ruiten
$types = array(
	1  => 'A', # Aas
	11 => 'B', # Boer
	12 => 'V', # Vrouw
	13 => 'K');# Koning

if(isset($_GET['soort'],$_GET['getal']) AND ctype_digit($_GET['soort']) AND ctype_digit($_GET['getal']) AND $_GET['soort'] >= 1 AND $_GET['soort'] <= 4 AND $_GET['getal'] >= 1 AND $_GET['getal'] <= 13):

	header("Content-type: image/png");
	$im = @imagecreate(50, 100)
	    or die("Cannot Initialize new GD image stream");
	    
	// Set background color
	$background_color = imagecolorallocatealpha($im, 255, 255, 255, 0);
	
	// Set font color
	$text_color = ($_GET['soort'] > 2) ? imagecolorallocate($im, 255, 0, 0) : imagecolorallocate($im, 0, 0, 0);
	
	// Set x from number
	$left = ($_GET['getal'] == 10) ? 10 : 20;
	
	// Set numbers
	$getal = ($_GET['getal'] <= 10) ? (($_GET['getal'] != 1) ? $_GET['getal'] : $types[$_GET['getal']]) : $types[$_GET['getal']];	
	
	// Replace path by your own font path
	$font = 'fonts/arial.ttf';
	
	// Make border lines
	imageline($im, 5, 0, 45, 0, $text_color);
	imageline($im, 49, 5, 49, 95, $text_color);
	imageline($im, 45, 99, 5, 99, $text_color);
	imageline($im, 0, 5, 0, 95, $text_color);
	
	// Make border angles	
	imagearc ($im , 45 , 95 , 10 , 10 , 0 , 90 , $text_color);
	imagearc ($im , 4 , 95 , 10 , 10 , 90 , 180 , $text_color);
	imagearc ($im , 4 , 4 , 10 , 10 , 180 , 270 , $text_color);
	imagearc ($im , 45 , 4 , 10 , 10 , 270 , 0 , $text_color);
	
	// Color of the card
	imagefill($im, 5, 5, imagecolorallocate($im, 255, 255, 255));
	
	// Set type
	imagettftext($im, 20, 0, 0, 17, $text_color, $font, $soorten[$_GET['soort']]);
	imagettftext($im, 20, 180, 50, 82, $text_color, $font, $soorten[$_GET['soort']]);
	
	// Set number
	imagettftext($im, 20, 0, $left, 60, $text_color, $font, $getal);
	
	imagepng($im);
	imagedestroy($im);
endif;
?>
example.php
<?php
for($i=1;$i<=4;$i++):
	for($u=1; $u<=13;$u++):
		echo '<img src="cards.php?soort='.$i.'&getal='.$u.'"/>';
	endfor;
endfor;
?>

Reacties

0
Nog geen reacties.