Recently popular color words, the following is a simple implementation method:
Recently popular color words, the following is a simple implementation method:
A simple realization of the color word
The following are the referenced contents:
Header ("Content-type:image/png");
$text = $_get[' t '];
$font = ' Stxingka.ttf '; TTF fonts
$fontsize = 30;
$size = Imagettfbbox ($fontsize, 0, $font, $text); Get font Width Range
$DX = ABS ($size [2]-$size [0]) +10;
$dy = ABS ($size [5]-$size [3]);
Building images
$im = Imagecreate ($DX, $dy);
Imagecolorallocate ($im, 255,255, 255); Background color
$fontcolor = Imagecolorallocate ($im, 255, 0, 0); Font Color
Imagettftext ($im, $fontsize, 0, 0, ABS ($size [5]), $fontcolor, $font, $text);
Imagepng ($im);
Imagedestroy ($im);
The above program just expresses some of the basic principles of color words, to achieve more complex and beautiful color words, all you have to do is change the font, change the font color, add some background map, and then consider caching, and so on, the method is similar, friends can try their own.
Two. Color Word application
The above program produces the color word through "t= text" to pass, but should note that these words are best to use UrlEncode to encode, of course, the length should also have limitations, this is not the scope of this article discussed.
In addition, generate the color Word program and the program that transmits the text uses UTF-8 code, if not, manual turn.
To use the color Word, only need to use can, of which, color.php to generate color Word program (that is, the above program), XXX for UrlEncode encoded text (used to generate color words)
Three. Smarty Plugin
Create a new file modifier.ubb.php in the plugins directory of Smarty, which reads as follows:
The following are the referenced contents:
function Smarty_modifier_ubb ($string) {
$ubb = Array (
'/\[b\] (. +?) \[\/b\]/i ', #加粗
'/\[url= (. +?) \](.+?) \[\/url\]/i ', #url
'/\[colorfont\] (. +?) \[\/colorfont\]/ie ' #彩字, note, to add the E modifier
);
$tohtml = Array (
' <b>\\1</b> ',
' <a href= ' \\1 ' >\\2</a> ',
' " '
);
The above is just the implementation of UBB, more UBB tag friends can be achieved by way of their own, where the color.php root according to the actual to modify
Return Preg_replace ($ubb, $tohtml, $string);
}
So, to display the color Word, just add it to the content
[Colorfont] text [/colorfont]
When displayed, use the UBB modifier in the smarty template, such as {$contentubb}