Implement gradient font output in PHP

Source: Internet
Author: User
Tags array count implement strlen
Gradient

First show:

It's just written today, it's still hot, the code is as follows:

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

$txt =$_get[' txt ']. " (Refresh I will change color OH) ";
$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);
$color 1=imagecolorallocate ($im, 255,128,128);
$red =imagecolorallocate ($im, 255,0,0);
$color 3=imagecolorallocate ($im, 128,64,64);
$yellow =imagecolorallocate ($im, 255,255,0);
$color 4=imagecolorallocate ($im, 255,128,0);
$color 5=imagecolorallocate ($im, 128,128,0);
$green =imagecolorallocate ($im, 0,255,0);
$color 6=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 ($color 1, $red, $color 3, $color 4, $color 5, $green, $color 6, $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, 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, 0, $x, $y, $color, "TUPIAN/FINISH/SIMSUN.TTC", $txt [$t]);
$x +=16;
}
}
Imagepng ($im);
Imagedestroy ($im);

?>


Usage Description: Save the above code as 1.php!

1, in the browser input http://your URL/1.php?txt= text can directly watch the effect
2, in the forum in this form of posting: {img}http://your URL/1.php?txt= text {/img} (when the braces are replaced with brackets for the actual use)

PS: If your space does not support the Mb_convert_encoding function, you need to have gb2312 to utf-8 function to support Chinese!



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.