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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| <?php
session_start();
$strlen= (int)4;
$width = $strlen * 30 + 21;
$height = 60;
// création
$img = imagecreatetruecolor($width,$height)or die ("Impossible de crée un flux d'image GD");
// antialising, c'est plus bô! :-)
imageantialias( $img, 1 );
// chaine
$string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$chaine = '';
for( $i = 0; $i < $strlen; $i++ ){
$chaine .= $string[ mt_rand( 0, 35 ) ];
$_SESSION['spood'] = $chaine;
// couleur de départ
$c1 = array( mt_rand( 200, 255), mt_rand( 200, 255), mt_rand( 200, 255) );
// couleur finale
$c2 = array( mt_rand( 150, 200), mt_rand( 150, 200), mt_rand( 150, 200) );
$colors = array(
imagecolorallocate( $img, 70, 130, 255 ) ,
imagecolorallocate( $img, 255, 237, 175 ),
imagecolorallocate( $img, 166, 250, 186 ),
imagecolorallocate( $img, 253, 188, 251 ),
imagecolorallocate( $img, 255, 255, 255 )
);
}
// création de l'image
for( $i = 0; $i < $width; $i++ ){
$r = $c1[0] + $i * ( $c2[0] - $c1[0] ) / $width;
$v = $c1[1] + $i * ( $c2[1] - $c1[1] ) / $width;
$b = $c1[2] + $i * ( $c2[2] - $c1[2] ) / $width;
$color = imagecolorallocate( $img, $r, $v, $b );
imageline( $img, $i, 0, $i, $height, $color );
}
// caractères
for( $i = 0; $i < $strlen; $i++ ){
$col = imagecolorallocate( $img, mt_rand( 0, 120 ),mt_rand( 0, 120 ), mt_rand( 0, 120 ));
imagettftext( $img, mt_rand( 20, 25 ),
mt_rand( -30, 30 ),
10 + $i * 30, 35,
$col,
'comic.ttf',
$chaine[ $i ] );
}
// quelques lignes qui embêtent
for( $i = 0; $i < 8; $i++ ){
imageline( $img, mt_rand(0, $width),
mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $colors[mt_rand( 0, 4 )] );
}
$noir = imagecolorallocate( $img, 0, 0, 0 );
// bordure
imageline( $img, 0, 0, $width, 0, $noir );
imageline( $img, 0, 0, 0, $height, $noir );
imageline( $img, $width - 1, 0, $width - 1, $height, $noir );
// header: image
header("Content-type: image/png");
imagepng( $img );
imagedestroy( $img );
?> |
Partager