Home > Backend Development > PHP Tutorial > Use PHP to implement gradient font output_PHP tutorial

Use PHP to implement gradient font output_PHP tutorial

WBOY
Release: 2016-07-13 17:34:17
Original
1017 people have browsed it

Let’s demonstrate first:

I just wrote it today and it’s still hot. The code is as follows:

Header("Content-type: image/png");

$txt=$_GET[txt]."(The color will change when I refresh it)";
$i=strlen($txt);
$width=16*strlen($txt);
$height=42*(int)($width/500+1);
$im = imagecreate($width,$height);

$background_color=imageColorAllocate($im,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,0,0,255);
$pink=imageColorAllocate($im,255,0,128);
$black=imageColorAllocate($im,0,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)
        {
                                                                                                                                                                                                                                                                                                          our                    {
                              $x=1;
                                                                                                                                                                                                                  to                             $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);

?>


使用说明:将上面的代码保存为1.php!

1、在浏览器中输入http://你的网址/1.php?txt=文字  可直接观看效果
2、在
论坛中以这样的形式发帖:{img}http://你的网址/1.php?txt=文字{/img}(实际用时把大括号换为中括号)

PS:如果你的空间不支持mb_convert_encoding函数,你需要有把gb2312转为utf-8的函数才能支持中文!

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/508496.htmlTechArticle先演示一下: 今天刚写的,还热乎着呢,代码如下: ?php Header(Content-type: image/png); $txt=$_GET[txt].(刷新我会变色哦); $i=strlen($txt); $width=16*str...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template