PHP中GD2的运用,注意编码格式的改变,以及head()函数之前不能有任何html元素包括空格!!!

<?php
    header ( "Content-type: text/html; charset=utf-8" ); //设置文件编码格式
    header("Content-type: image/jpeg");     //告知浏览器所要输出图像的类型
    $img = imagecreate(100, 50);     //创建画布
    $bg = imagecolorallocate($img, 255, 255, 255);     //定义背景颜色
    $red = imagecolorallocate($img, 255, 0, 0);     //设置字符串颜色
    $text="I like PHP";
    iconv("gbk","utf-8", $text);// 将GBK编码格式转换成UTF-8格式
    imagestring($img, 5, 0, 0, $text, $red);      //输出英文字符串
    imagejpeg($img);         //输出图像
    imagedestroy($img);                             //释放内存
?>

 

posted @ 2015-09-06 15:24  骏码信息  阅读(288)  评论(0编辑  收藏  举报