First, let's take a look at it. the code is as follows :? PhpHeader ("Content-type: image/png"); $ txt = $ _ GET ['txt ']. "(I will change the color when refreshing)"; $ I = strlen ($ txt); $ width = 16 * strlen ($ txt); $ height = 42 * (int) ($ width
First, let's demonstrate:
The code is as follows:
Header ('content-type: image/png ');
$ Txt = $ _ GET ['txt '].' (I will change the color when refreshing )';
$ I = strlen ($ txt );
$ Width = 16 * strlen ($ txt );
$ Height = 42 * (int) ($ width/500 1 );
$ Im = imagecreate ($ width, $ height );
$ Background_color = imageColorAllocate ($ instant, 223,223,223 );
$ White = imageColorAllocate ($ im, 255,255,255 );
$ Color1 = imageColorAllocate ($ im, 255,128,128 );
$ Red = imageColorAllocate ($ im, 255, 0, 0 );
$ Color3 = imageColorAllocate ($ im, 128,64, 64 );
$ Yellow = imageColorAllocate ($ im, 255,255, 0 );
$ Color4 = imageColorAllocate ($ im, 255,128, 0 );
$ Color5 = imageColorAllocate ($ im, 128,128, 0 );
$ Green = imageColorAllocate ($ im, 0,255, 0 );
$ Color6 = imageColorAllocate ($ im, 0,128, 0 );
$ Blue = imageColorAllocate ($ im, 255 );
$ Pink = imageColorAllocate ($ im, 128 );
$ Black = imageColorAllocate ($ im, 0, 0 );
$ Array = array ($ color1, $ red, $ color3, $ color4, $ color5, $ green, $ color6, $ blue, $ pink, $ black, $ white );
$ X = 1;
$ Y = 40;
$ Count = 1;
For ($ t = 0; $ t <$ I; $ t)
{
$ Temp = rand (0, 10 );
$ Color = $ array [$ temp];
If (ord ($ txt [$ t])> = 128)
{
If ($ * 32> 500)
{
$ X = 1;
$ Y = 40 $ count * 41;
$ Count;
}
$ Temp = $ txt [$ t]. $ txt [$ t];
$ Temp = mb_convert_encoding ($ temp, 'utf-8', 'gb2312 ');
Imagettftext ($ im, 24, 0, $ x, $ y, $ color, 'tupian/finish/simsun. ttc ', $ temp );
$ X = 32;
}
Else
{
If ($ x 8> 500)
{
$ X = 1;
$ Y = 40 $ count * 41;
$ Count;
}
Imagettftext ($ im, 24, 0, $ x, $ y, $ color, 'tupian/finish/simsun. ttc ', $ txt [$ t]);