Os dejo el código escrito y un zip preparado:
Código:
<?php
header("Content-type: image/png");
$im = imagecreatetruecolor(200, 50);
$bg = imagecolorallocate($im, mt_rand(175,255), mt_rand(175,255), mt_rand(175,255));
imagefilledrectangle($im, 0, 0, 199, 49, $bg);
$texto = array("0","1","2","3","4","5","6","7","8","9","a","b","c","x","y","z");
$fonts = array("bauhs93.ttf","bernhc.ttf","bradhitc.ttf","castelar.ttf","comic.ttf","couri.ttf","goudysto.ttf","impact.ttf","tahoma.ttf","verdana.ttf");
$reg = 200 / 7;
$rog = 50 / 4;
$rag = 200 / 6;
for ($i = 1; $i <= 6; $i++) {
//ESCRIBE TEXTO//
$t_color = imagecolorallocate($im, mt_rand(0,100), mt_rand(0,100), mt_rand(0,100));
imagettftext($im, mt_rand(20,30), mt_rand(-20,20), mt_rand(($reg * $i)-3,($reg * $i)+3)-10, mt_rand(30,40), $t_color, $fonts[mt_rand(0,9)], $texto[mt_rand(0,15)]);
}
for ($i = 1; $i <= 3; $i++) {
//LINEAS HORIZONTALES//
$hl_color = imagecolorallocate($im, mt_rand(150,255), mt_rand(150,255), mt_rand(150,255));
$var = mt_rand(-5,5);
imageline($im,0,$rog * $i,200,$rog * $i + $var,$hl_color);
}
for ($i = 1; $i <= 5; $i++) {
//LINEAS VERTICALES//
$hl_color = imagecolorallocate($im, mt_rand(150,255), mt_rand(150,255), mt_rand(150,255));
$var = mt_rand(-3,3);
imageline($im,$rag * $i,0,$rag * $i + $var,50,$hl_color);
}
for ($i = 1; $i <= 50; $i++) {
//CRUCES//
$tmp = mt_rand(1,50);
$color1 = imagecolorallocate($im, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255));
$color2 = imagecolorallocate($im, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255));
$color3 = imagecolorallocate($im, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255));
$color4 = imagecolorallocate($im, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255));
$color5 = imagecolorallocate($im, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255));
$color6 = imagecolorallocate($im, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255));
$color7 = imagecolorallocate($im, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255));
$color8 = imagecolorallocate($im, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255));
$color9 = imagecolorallocate($im, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255));
imagesetpixel($im,$i*4,$tmp,$color1);
imagesetpixel($im,$i*4+1,$tmp+1,$color2);
imagesetpixel($im,$i*4+2,$tmp+2,$color3);
imagesetpixel($im,$i*4+1,$tmp-1,$color4);
imagesetpixel($im,$i*4+2,$tmp-2,$color5);
imagesetpixel($im,$i*4-1,$tmp+1,$color6);
imagesetpixel($im,$i*4-2,$tmp+2,$color7);
imagesetpixel($im,$i*4-1,$tmp-1,$color8);
imagesetpixel($im,$i*4-2,$tmp-2,$color9);
}
$borde = imagecolorallocate($im, mt_rand(0,150), mt_rand(0,150), mt_rand(0,150));
imagerectangle($im,0,0,199,49,$borde);
imagerectangle($im,1,1,198,48,$borde);
imagepng($im);
?>
header("Content-type: image/png");
$im = imagecreatetruecolor(200, 50);
$bg = imagecolorallocate($im, mt_rand(175,255), mt_rand(175,255), mt_rand(175,255));
imagefilledrectangle($im, 0, 0, 199, 49, $bg);
$texto = array("0","1","2","3","4","5","6","7","8","9","a","b","c","x","y","z");
$fonts = array("bauhs93.ttf","bernhc.ttf","bradhitc.ttf","castelar.ttf","comic.ttf","couri.ttf","goudysto.ttf","impact.ttf","tahoma.ttf","verdana.ttf");
$reg = 200 / 7;
$rog = 50 / 4;
$rag = 200 / 6;
for ($i = 1; $i <= 6; $i++) {
//ESCRIBE TEXTO//
$t_color = imagecolorallocate($im, mt_rand(0,100), mt_rand(0,100), mt_rand(0,100));
imagettftext($im, mt_rand(20,30), mt_rand(-20,20), mt_rand(($reg * $i)-3,($reg * $i)+3)-10, mt_rand(30,40), $t_color, $fonts[mt_rand(0,9)], $texto[mt_rand(0,15)]);
}
for ($i = 1; $i <= 3; $i++) {
//LINEAS HORIZONTALES//
$hl_color = imagecolorallocate($im, mt_rand(150,255), mt_rand(150,255), mt_rand(150,255));
$var = mt_rand(-5,5);
imageline($im,0,$rog * $i,200,$rog * $i + $var,$hl_color);
}
for ($i = 1; $i <= 5; $i++) {
//LINEAS VERTICALES//
$hl_color = imagecolorallocate($im, mt_rand(150,255), mt_rand(150,255), mt_rand(150,255));
$var = mt_rand(-3,3);
imageline($im,$rag * $i,0,$rag * $i + $var,50,$hl_color);
}
for ($i = 1; $i <= 50; $i++) {
//CRUCES//
$tmp = mt_rand(1,50);
$color1 = imagecolorallocate($im, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255));
$color2 = imagecolorallocate($im, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255));
$color3 = imagecolorallocate($im, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255));
$color4 = imagecolorallocate($im, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255));
$color5 = imagecolorallocate($im, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255));
$color6 = imagecolorallocate($im, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255));
$color7 = imagecolorallocate($im, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255));
$color8 = imagecolorallocate($im, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255));
$color9 = imagecolorallocate($im, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255));
imagesetpixel($im,$i*4,$tmp,$color1);
imagesetpixel($im,$i*4+1,$tmp+1,$color2);
imagesetpixel($im,$i*4+2,$tmp+2,$color3);
imagesetpixel($im,$i*4+1,$tmp-1,$color4);
imagesetpixel($im,$i*4+2,$tmp-2,$color5);
imagesetpixel($im,$i*4-1,$tmp+1,$color6);
imagesetpixel($im,$i*4-2,$tmp+2,$color7);
imagesetpixel($im,$i*4-1,$tmp-1,$color8);
imagesetpixel($im,$i*4-2,$tmp-2,$color9);
}
$borde = imagecolorallocate($im, mt_rand(0,150), mt_rand(0,150), mt_rand(0,150));
imagerectangle($im,0,0,199,49,$borde);
imagerectangle($im,1,1,198,48,$borde);
imagepng($im);
?>
Aprobecho tambien para preguntar si las imagenes generadas son faciles o dificiles para ser interpretadas por un programa.
Se que hay cosas por mejorar:
1) Meter un config.php como include para poner variables globales
2) Hacer una matriz de colores para no usar tanto imagecolorallocate
3) Mejoras en general