项目描述:由于要作打印的产品价格贴,须要美观度,产品名字须要颜色渐变。php
这里很是感谢ThinkPHP 峰会4 里面的大神们。 @[厦门]伍拾步 @[上海]beyond @[江苏]囧NC @【浙江】幸福 @泰安sunny字体
有兴趣的能够加入哦 群号43321338
效果图展现 code
<?php $txt="祝群里的大神们永结同心!"; $width=500;//图片宽度 $height=500;//图片高度 //建立一张图片 function createImg($width,$height,$txt) { $im = imagecreate($width, $height); $bgcolor = imagecolorallocate($im, 255, 255, 255); imagefill($im, 0, 0, $bgcolor); $black = imagecolorallocate($im, 0, 0, 0); $font = getcwd() . "/1.TTF"; //打上文字 字体大点 记住是黑色 活着比较奇葩的颜色 不要和背景重复 imagettftext($im, 30, 0, 10, 200, $black, $font, $txt); //而后取样覆盖颜色 从左到右边 从上到下 $red = 0; $colornum = 0; $ok = true; for ($i = 0; $i < $height; $i++) { //这里是纵向渐变 if ($ok) { $red = 210 - $colornum * 2; $green = 176 - $colornum * 2; $blue = 102 - $colornum * 2; $color = imagecolorallocate($im, $red, $green, $blue); $colornum++; $ok = false; } for ($j = 0; $j < $width; $j++) { $rs = imagecolorat($im, $j, $i); if ($rs == 0) { //这里不取色 } else { $t = imagesetpixel($im, $j, $i, $color); $ok = true; } } } $newfile = getcwd() . "/font.jpg"; imagejpeg($im, $newfile, 100); ImageDestroy($im); }