imagestring不支持中文,改用imagettftext
2016-11-25 15:00
232 查看
想在图片上画点东西,手册上是imagestring,但是不支持中文,改用imagettftext,但是imagettftext需要引入字体,网上随便下载一下就可以了。
效果:
代码如下:
$width = 600;
$height = 650;
header("Content-type: image/gif; charset=utf-8");
$img = imagecreate($width, $height);
$bg_color = imagecolorallocate($img, 0, 0, 0);
$red = imagecolorallocate($img, 255, 0, 0);
$font = "./font/1.ttf";
$sting = '我的心就如这颗笛卡尔的情书!';
imagettftext($img, 20, 0, 5, 200, $red, $font, $sting);
$sting = '很遗憾不能再为您服务!如有疑问请联系管理员!';
imagettftext($img, 20, 0, 5, 300, $red, $font, $sting);
//imagestring ($img , 5 , 300 , 300 , $sting , $red );
for ($i = 0; $i <= 100; $i++) {
for ($j = 0; $j <= 100; $j++) {
$r = M_PI / 50 * $i * (1 - sin(M_PI / 50 * $j)) * 40;
$x = $r * cos(M_PI / 50 * $j) * sin(M_PI / 50 * $i) + $width / 2;
$y = -$r * sin(M_PI / 50 * $j) + $height / 6;
imagesetpixel($img, $x, $y, $red);
}
}
imagegif($img);
imagedestroy($img);
exit;
效果:
代码如下:
$width = 600;
$height = 650;
header("Content-type: image/gif; charset=utf-8");
$img = imagecreate($width, $height);
$bg_color = imagecolorallocate($img, 0, 0, 0);
$red = imagecolorallocate($img, 255, 0, 0);
$font = "./font/1.ttf";
$sting = '我的心就如这颗笛卡尔的情书!';
imagettftext($img, 20, 0, 5, 200, $red, $font, $sting);
$sting = '很遗憾不能再为您服务!如有疑问请联系管理员!';
imagettftext($img, 20, 0, 5, 300, $red, $font, $sting);
//imagestring ($img , 5 , 300 , 300 , $sting , $red );
for ($i = 0; $i <= 100; $i++) {
for ($j = 0; $j <= 100; $j++) {
$r = M_PI / 50 * $i * (1 - sin(M_PI / 50 * $j)) * 40;
$x = $r * cos(M_PI / 50 * $j) * sin(M_PI / 50 * $i) + $width / 2;
$y = -$r * sin(M_PI / 50 * $j) + $height / 6;
imagesetpixel($img, $x, $y, $red);
}
}
imagegif($img);
imagedestroy($img);
exit;
相关文章推荐
- PHP 支持中文按固定长度分割字符串 适用于imagettftext
- Android 利用Java实现压缩与解压缩(zip、gzip)支持中文路径
- 让MySQL支持中文
- C# DES 加密/解密,支持文件和中文/UNICODE字符,返回BASE64编码字符串
- Qt之QString中文支持
- DNS的查找机制、中文扩展,及其对手机扫描商标名称的支持
- debian添加中文支持
- c# VideoWriter保存的视频不支持中文路径
- Linux 服务器设置成支持中文
- 让RequisitePro支持中文RUP模板
- 让Tomcat支持中文路径名和中文文件名
- 在sublime text 3中安装中文支持
- python实现支持unicode中文的AC自动机
- Linux 服务器设置成支持中文
- sublimeText编辑器,不支持中文鼠标跟随的问题
- 使用VS2008开发MFC,如何支持中文输入?
- 运用hadoop计算TF-IDF续-支持中文读取-支持文件输出控制
- PHP 中文简繁互转代码 完美支持大陆、香港、台湾及新加坡
- java数字切换成中文(支持万位以下)
- IIS下配置WordPress永久链接支持中文完美方法