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
| <?php
header("Content-type: image/jpeg");
//-----------------------------
// Valeurs tests
//-----------------------------
$name = 'muse';
$color = 'FFFFFF';
$dirpolice = 'freshbot.ttf';
//-----------------------------
// Largeur - Hauteur
//-----------------------------
$textsize = imagettfbbox(8.2, 0, $dirpolice, $name);
$x = abs($textsize[4]) + abs($textsize[6]);
$y = abs($textsize[1]) + abs($textsize[7]);
$countx = ceil(100 / $x);
$county = ceil(100 / $y);
//-----------------------------
// Création de l'image & couleur
//-----------------------------
$im = @imagecreate(100, 100);
$red = hexdec(substr($color, 0, 2));
$green = hexdec(substr($color, 2, 2));
$blue = hexdec(substr($color, 4, 2));
$background_color = imagecolorallocate($im, $red, $green, $blue);
//-----------------------------
// Ecriture
//-----------------------------
for ($i = 1; $i <= $county; $i++)
{
$posy = $i * $y;
for ($u = 0; $u < $countx; $u++)
{
$posx = $u * $x;
$r = rand(0, 240);
$v = rand(0, 240);
$b = rand(0, 240);
while ($r == $red && $v == $green && $b == $blue)
{
$r = rand(0, 240);
$v = rand(0, 240);
$b = rand(0, 240);
}
$textcolor = imagecolorallocate($im, $r, $v, $b);
imagettftext($im, 8.2, 0, $posx, $posy, $textcolor, $dirpolice, $name);
unset($textolor);
}
}
imagejpeg($im);
imagedestroy($im);
?> |
Partager