2013-01-23 99 views
0

我试图改变$font_size但现在看来,这是行不通的。无论如何,它都保持不变。即使我改变了$font_size高达130它保持不变:PHP FONT_SIZE验证码问题

<?php 
    header('Content-type: image/png'); 

    $rand_num = rand(1000, 9999); 

    $font_size = 130; 

    $image_width = 110; 
    $image_height = 20; 

    $image = imagecreate($image_width, $image_height); 
    imagecolorallocate($image, 255, 255, 255); 
    $black_color = imagecolorallocate($image, 0, 0, 0); 

    imagestring($image, $font_size, 0, 0, $rand_num, $black_color); 

    for($x=0; $x <= 30; $x++){ 
     $x1 = rand(1, 100); 
     $y1 = rand(1, 100); 
     $x2 = rand(1, 100); 
     $y2 = rand(1, 100); 

     imageline($image, $x1, $y1, $x2, $y2, $black_color); 
    } 

    imagepng($image); 
?> 

回答

0

PHP Manual,字体参数

可以是1,2,3,4,5内置在拉丁文2编码字体(在相当于较大的字体 较高的数字)或任何自己的字体与imageloadfont注册 标识符()。

所以你要尝试1 2 3 4 5,而不是130

+0

那么对于latin2编码的内置字体,最大值只能是5呢? – user1995927

+0

是的,这是正确的,否则你可以使用imageloadfont() –

+0

imageloadfont加载自定义字体()?它与imagettftext()相同吗? – user1995927

0

您可以更改使用imagettftext功能的字体大小。

imagettftext($image, $font_size, $angle, $x, $y, $text_color, '$font-family', $text); 

    $image is the $imagecreate function 
    $font_size is the size of font you want. 
    $angle is the angle of the fonts tilted 
    $x and $y are coordinates. 
    $text_color is the imagecolorallocate function 
    $font-family is the family of font you want to use 
    $text is the text or random text to be displayed