首页 > php代码 > 给图片添加文字(支持中文) // PHP函数

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

<?php
// **************************************** // 
// 功能:给图片添加文字
// 参数: $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); //结束图形,释放内存空间 
}


本文链接:http://www.phprm.com/code/730ef3f9bc9f3010bef5e096fb5fc59a.html

收藏随意^^请保留教程地址.

标签:none

发表留言