Colored characters are popular recently, here is a simple way to implement them:
1. Simple implementation of colorful characters
以下为引用的内容: header("content-type: image/png"); $text = $_get[t]; $font = stxingka.ttf; //ttf字体 $fontsize = 30; $size = imagettfbbox($fontsize, 0, $font, $text); //获得字体长宽范围 $dx = abs($size[2]-$size[0]) +10; $dy = abs($size[5]-$size[3]); //构建图像 $im = imagecreate($dx,$dy); imagecolorallocate($im, 255,255, 255); //背景色 $fontcolor = imagecolorallocate($im, 255, 0, 0); //字体颜色 imagettftext($im, $fontsize, 0, 0, abs($size[5]), $fontcolor, $font, $text); imagepng($im); imagedestroy($im); |
The above program only expresses some basic principles of color words. To achieve more complex and beautiful color words, all you need to do is to change the font, change the font color, add some background images, and then consider caching, etc. The methods are similar, friends can try it themselves.
2. Color word application
The colored words generated by the above program are transmitted through "?t=text", but it should be noted that these words are best encoded with urlencode. Of course, the length should also be limited. This is not discussed in this article. Range.
In addition, the program that generates colored words and the program that transmits text both use utf-8 encoding. If not, convert it manually...
To use colored words, just use That's it, where color.php is the program that generates colored words (that is, the program above), and xxx is the text encoded by urlencode (used to generate colored words)
Three.smarty plug-in
Create a new file modifier.ubb.php in smarty’s plugins directory with the following content:
The following is the quoted content:
/[b](.+?)[/b]/i, #Bold //The above is just the implementation of ubb. Friends can implement more ubb tags according to the method. The color.php root is actually modified |