Scripts

I love...

Laten zien wat imagettftext, imagettfbbox en imagesetpixel allemaal kunnen bereiken. Ik het dit script in 10 minuten gemaakt, het meeste werk was uitzoeken welke pixel voor het hartje waar moest. Lettertype heet 04b08: http://phphulp.gamerswiki.nl/ilove/04b08.ttf Gewoon even opslaan in de zelfde dir als het script.

i-love
[code]<?php
	if (isset($_GET['text'])) {
		header("Content-type: image/png");
		
		function ilove ($text='Myself') {
			$width = imagettfbbox(6, 0, '04b08.ttf', 'I  ' . stripslashes(trim($text)));
			$img = imagecreate($width[2] + 10, 6); // +10 voor eventuele veiligheid
			
			$white = imagecolorallocate($img, 255, 255, 255);
			$red = imagecolorallocate($img, 213, 46, 39);
			$red2 = imagecolorallocate($img, 250, 136, 131);
			$black = imagecolorallocate($img, 0, 0, 0);
			
			imagesetpixel($img, 5, 2, $red2);
			imagesetpixel($img, 6, 1, $red);
			imagesetpixel($img, 6, 2, $red);
			imagesetpixel($img, 6, 3, $red);
			imagesetpixel($img, 7, 1, $red);
			imagesetpixel($img, 7, 2, $red);
			imagesetpixel($img, 7, 3, $red);
			imagesetpixel($img, 7, 4, $red);
			imagesetpixel($img, 8, 2, $red);
			imagesetpixel($img, 8, 3, $red);
			imagesetpixel($img, 8, 4, $red);
			imagesetpixel($img, 8, 5, $red);
			imagesetpixel($img, 11, 2, $red2);
			imagesetpixel($img, 10, 1, $red);
			imagesetpixel($img, 10, 2, $red);
			imagesetpixel($img, 10, 3, $red);
			imagesetpixel($img, 9, 1, $red);
			imagesetpixel($img, 9, 2, $red);
			imagesetpixel($img, 9, 3, $red);
			imagesetpixel($img, 9, 4, $red);
			
			imagettftext($img, 6, 0, 1, 6, $black, '04b08.ttf', 'I  ' . stripslashes(trim($text)));
	
			imagepng($img);
			imagedestroy($img);
		}
		
		ilove($_GET['text']);
	} else {
?>
<input name="text" type="text" value="Myself" onkeyup="document.getElementById('ilove').src = 'ilove_' + escape(this.value) + '.png';" />
<div id="test"></div>
<img src="ilove_myself.png" id="ilove" />
<?php } ?>[/code]

.htacces (voor het opslaan als gedoe):
[code]RewriteEngine On
RewriteRule ^ilove_(.*).png$ ilove.php?text=$1 [L,QSA][/code]

Reacties

0
Nog geen reacties.