|
First, let's demonstrate: The Code is as follows:
|
|
<? Php 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 ($ x + 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]); $ X + = 16; } } ImagePNG ($ im ); ImageDestroy ($ im ); ?> |
|
Usage instructions: Save the above Code as 1.php! 1. Enter http: // your url/1.php? in the browser? Txt = text can be viewed directly 2. Post in the Forum in the form of {img} http: // your url/1.php? Txt = text {/img} (braces are replaced with brackets in actual use) PS: If your space does not support the mb_convert_encoding function, you need to convert gb2312 to UTF-8 to support Chinese characters! |