一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

给图片添加文字(支持中文) // PHP函数

时间:2008-04-24 编辑:简简单单 来源:一聚教程网

// **************************************** //
// 功能:给图片添加文字
// 参数: $img 图片文件名
// $new_img 另存图片文件名,如果为空表示不另存图片
// $text 字符串内容
// text_size 字符串大小
// text_angle 字型串输出角度
// text_x 字符串输出 x 坐标
// text_y 字符串输出 y 坐标
// $text_font 字型文件名
// $r,$g,$b 字符串颜色RGB值
// **************************************** //
function img_text($img, $new_img, $text, $text_size, $text_angle, $text_x, $text_y, $text_font, $r, $g, $b){

$text=iconv("gb2312","UTF-8",$text);
Header("Content-type: image/gif");
$im = @imagecreatefromstring(file_get_contents($img)) or die ("打开图片失败!");
$color = ImageColorAllocate($im, $r,$g,$b);

//ImageTTFText(int im, int size, int angle, int x, int y, int col, string fontfile, string text):
//本函数将 TTF (TrueType Fonts) 字型文字写入图片。
//参数: size 为字形的尺寸;
// angle 为字型的角度,顺时针计算,0 度为水平(由左到右),90 度则为由下到上的文字;
// x,y 二参数为文字的坐标值 (原点为左上角);
// col 为字的颜色;
// fontfile 为字型文件名称;
// text 是字符串内容。
ImageTTFText($im, $text_size, $text_angle, $text_x, $text_y, $color, $text_font, $text);

if ($new_img==""):
ImageGif($im); // 不保存图片,只显示
else:
ImageGif($im,$new_img); // 保存图片,但不显示
endif;

ImageDestroy($im); //结束图形,释放内存空间


?>

热门栏目