Imagestring
Ik ben nu al een tijdje bezig om een plaatje te krijgen, en ik probeer nu de font te veranderen. Ik heb alleen geen flauw idee wat ik verkeerd doe. Zou iemand mij kunnen helpen?
$image = imagecreatetruecolor(300, 50);
$color = imagecolorallocate($image, 999,999,999);
$textcolor = imagecolorallocate($image, 0, 0 ,0);
$font = 'travelerl.ttf';
imagefill($image, 0, 0, $color );
imagettftext ($image, 10 , 10, 0, 0, $textcolor , $font , 'hello' );
imagepng($image, 'captcha.png');
echo '<img src="captcha.png"/>';
Ps. ik heb de font al geupload en in de zelfde map gezet :).
$image = imagecreatetruecolor(300, 50);
$color = imagecolorallocate($image, 999,999,999);
$textcolor = imagecolorallocate($image, 0, 0 ,0);
$font = 'travelerl.ttf';
imagefill($image, 0, 0, $color );
imagettftext ($image, 10 , 10, 0, 0, $textcolor , $font , 'hello' );
imagepng($image, 'captcha.png');
echo '<img src="captcha.png"/>';
Ps. ik heb de font al geupload en in de zelfde map gezet :).
Wat gaat er mis?
Waarom doe je niet gewoon dit php script de data outputten? (Dus niet naar bestand schrijven. Moet sowieso haast wel met captcha enzo.)
Waarom doe je niet gewoon dit php script de data outputten? (Dus niet naar bestand schrijven. Moet sowieso haast wel met captcha enzo.)
index.php
captcha.php
dit is hoe ik mijn captcha heb, nu zou ik dus graag mijn font aan willen passen, maar hoe doe ik dat?
Quote:
<html>
<head>
</head>
<body>
<br />
<form action="captcha.php" method="post">
vul het in:
<input type="text" name="captcha"/>
<input type="submit" name="submit" value="verzenden"/>
</body>
</html>
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
session_start();
if(isset($_SESSION['terug'])){
header("Refresh: 0;");
unset($_SESSION['terug']);
}
function string($number){
if(!is_numeric($number)){
$number = 10;
}
$letter = range(a,z);
$hoofletter = range(A,Z);
$cijfers = range(0,9);
$alles = array_merge($letter, $hoofletter, $cijfers);
for($bas=0;$bas<$number;$bas++){
$code.= $alles[rand(0,count($alles)-1)];
}
return $code;
}
$_SESSION['code'] = string(4);
$image = imagecreatetruecolor(300, 50);
$color = imagecolorallocate($image, 999,999,999);
$textcolor = imagecolorallocate($image, 0, 0 ,0);
$font = 'travelerl.ttf';
imagefill($image, 0, 0, $color );
imagestring($image, 14, 20, 0,$_SESSION['code'], 20);
imagettftext ($image, 10 , 10, 0, 0, $textcolor , $font , 'hello' );
imagepng($image, 'captcha.png');
echo '<img src="captcha.png"/>';
?>
session_start();
if(isset($_SESSION['terug'])){
header("Refresh: 0;");
unset($_SESSION['terug']);
}
function string($number){
if(!is_numeric($number)){
$number = 10;
}
$letter = range(a,z);
$hoofletter = range(A,Z);
$cijfers = range(0,9);
$alles = array_merge($letter, $hoofletter, $cijfers);
for($bas=0;$bas<$number;$bas++){
$code.= $alles[rand(0,count($alles)-1)];
}
return $code;
}
$_SESSION['code'] = string(4);
$image = imagecreatetruecolor(300, 50);
$color = imagecolorallocate($image, 999,999,999);
$textcolor = imagecolorallocate($image, 0, 0 ,0);
$font = 'travelerl.ttf';
imagefill($image, 0, 0, $color );
imagestring($image, 14, 20, 0,$_SESSION['code'], 20);
imagettftext ($image, 10 , 10, 0, 0, $textcolor , $font , 'hello' );
imagepng($image, 'captcha.png');
echo '<img src="captcha.png"/>';
?>
<html>
<head>
</head>
<body>
<br />
<form action="captcha.php" method="post">
vul het in:
<input type="text" name="captcha"/>
<input type="submit" name="submit" value="verzenden"/>
</body>
</html>
captcha.php
Quote:
dit is hoe ik mijn captcha heb, nu zou ik dus graag mijn font aan willen passen, maar hoe doe ik dat?
regel 37
Dit zou inderdaad moeten werken, maar dit doet het helaas niet. Ook kan ik de grootte van het lettertype niet aanpassen.
Ik heb deze code:
weergeeft:

Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php
//Start the session so we can store what the code actually is.
session_start();
//Now lets use md5 to generate a totally random string
$lett = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$text = str_shuffle($lett);
$string = substr($text,0,6);
$captcha = imagecreatefrompng("./captcha.png");
$font = './font.ttf';
$black = imagecolorallocate($captcha, 127, 127, 127);
$line = imagecolorallocate($captcha,233,239,239);
imageline($captcha,40,0,64,29,$line);
imagettftext($captcha, 20, 0, 15, 35, $black, $font, $string);
$_SESSION['key'] = $string;
header("Content-type: image/png");
imagepng($captcha);
?>
//Start the session so we can store what the code actually is.
session_start();
//Now lets use md5 to generate a totally random string
$lett = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$text = str_shuffle($lett);
$string = substr($text,0,6);
$captcha = imagecreatefrompng("./captcha.png");
$font = './font.ttf';
$black = imagecolorallocate($captcha, 127, 127, 127);
$line = imagecolorallocate($captcha,233,239,239);
imageline($captcha,40,0,64,29,$line);
imagettftext($captcha, 20, 0, 15, 35, $black, $font, $string);
$_SESSION['key'] = $string;
header("Content-type: image/png");
imagepng($captcha);
?>
weergeeft:
Helemaal top, ik weet al wat ik verkeer deed:
imagettftext ($image, 10 , 10, 0, 0, $textcolor , $font , 'hello' );
moet zijn:
imagettftext($image, 14, 0, 14, 30, $textcolor , $font , 'hello' );
imagettftext ($image, 10 , 10, 0, 0, $textcolor , $font , 'hello' );
moet zijn:
imagettftext($image, 14, 0, 14, 30, $textcolor , $font , 'hello' );




