Kan iemand een code maken die een plaatje maakt, met random tekst? Ik wil dit maken zodat je bij het aanmelden eerst de code van het plaatje in moet voeren.

De code voor een plaatje die hier ( http://www.phphulp.nl/forum/showtopic.php?cat=1&id=18690&lasttopic=1 ) al stond is dit:


<?php
// Set the content-type
header("Content-type: image/png");


// Create the image
$im = imagecreatetruecolor(400, 30);

// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);

// The text to draw
$text = 'Testing...';
// Replace path by your own font path
$font = 'arial.ttf';

// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);

// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);

// Using imagepng() results in clearer text compared with imagejpeg()
echo imagejpeg($im, "", "100");
imagedestroy($im);
?> 


Deze heb ik getest: http://www.xxx.nl/lol.php
Maar je krijgt zo te zien een soort error: ""De afbeelding “http://www.xxx.nl/lol.php” kan niet worden weergegeven, omdat hij fouten bevat.""

Maar goed, ik wil dus een plaatje, met random tekst (3 chars), waarbij je die drie chars toekent aan een variabele, die je kan checken in een form. Jullie hebben dit vast wel eens gezien bij het aanmelden ergens.

Ik hoop dat iemand dit kan?
oke
regel 27:

<?php
echo imagejpeg($im, "", "100");
?>

moet denk ik:

<?php
echo imagejpeg($im, NULL, "100");
?>

zijn


edit:

kijk je bron is:


Warning: imagettfbbox(): Could not find/open font in /home/borisbez/domains/xxx.nl/public_html/loll.php on line 12

Warning: imagecreatetruecolor(): Invalid image dimensions in /home/borisbez/domains/xxx.nl/public_html/loll.php on line 17

Warning: imagecolorallocate(): supplied argument is not a valid Image resource in /home/borisbez/domains/xxx.nl/public_html/loll.php on line 20

Warning: imagecolorallocate(): supplied argument is not a valid Image resource in /home/borisbez/domains/xxx.nl/public_html/loll.php on line 21

Warning: imagefilledrectangle(): supplied argument is not a valid Image resource in /home/borisbez/domains/xxx.nl/public_html/loll.php on line 24

Warning: imagecolortransparent(): supplied argument is not a valid Image resource in /home/borisbez/domains/xxx.nl/public_html/loll.php on line 25

Warning: imagettftext() expects parameter 1 to be resource, boolean given in /home/borisbez/domains/xxx.nl/public_html/loll.php on line 28

Warning: imagepng(): supplied argument is not a valid Image resource in /home/borisbez/domains/xxx.nl/public_html/loll.php on line 31

Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/borisbez/domains/xxx.nl/public_html/loll.php on line 32
Je stuurt een header (image/png) en wilt hem outputten als image/jpeg? Dat zal niet echt werken...
hmm, dat is een goeie jip :-p
hee mensen het is al gelukt:

http://www.xxx.nl/lol.php


<?php
header("Content-type: image/png");
$im = @imagecreate(100, 50)
   or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 255, 255, 255);
$text_color = imagecolorallocate($im, 233, 14, 91);
$num = rand(0, 9);
$num1 = rand(0, 9);
$num5 = rand(0, 9);
$code = $num . $num1 . $num5;
imagestring($im, 1, 5, 5,  "$code", $text_color);
imagepng($im);
imagedestroy($im);
?>


maar hij kan vast korter

en hoe kan ik doen dat hij ook letters pakt?
<?php
function randomgenerator($aantaltekens)
{
//Eerst maken we 3 arrays met gegevens.
$kleineletters = range('a','z');
$groteletters = range('A','Z');
$cijfers = range(0,9);

//Prop ze bij elkaar en tel ze.
$karakters = array_merge($kleineletters, $groteletters, $cijfers);
$aantal = count($karakters)-1;
$random = null;

//Voor ieder teken dat we willen maken pakken we een random nummertje.
for($i=0; $i < $aantaltekens; $i++) {
$random .= $karakters[mt_rand(0, $aantal)];
}
return $random;
}
?>
oke bedankt:-)

Reageren