我知道的有三种,都是使用GD库的image函数
一种是直接在图片上写文字
imagefttext();
一种是带透明度的水印图片
imagecopy();
还有一种是可以自定义水印图片透明度的
imagecopymerge();
你想要什么效果,可以接着细说
请确认C:\WINDOWS\Fonts\simkai.ttf';是否支持中文
或不要转换
直接
$str=$str;
$image?=?new?\Think\Image();?
php
/*PHP图片加文字水印类库
该类库暂时只支持文字水印,位置为右下角,颜色随机
调用方法:
①.、在需要加水印的文件顶部引入类库:
include_once 'imageClass.php';
$tpl=new image_fu;
$tpl-img(图片路径,水印文字,字体路径,字体大小,字体角度);
*/
class image_fu{
private $image;
private $img_info;
private $img_width;
private $img_height;
private $img_im;
private $img_text;
private $img_ttf='';
private $img_new;
private $img_text_size;
private $img_jd;
if(isset($img)file_exists($img)){//检测图片是否存在
$this-image =$img;
$this-img_text=$txt;
$this-img_text_size=$size;
$this-img_jd=$jiaodu;
if(file_exists($ttf)){
$this-img_ttf=$ttf;
}else{
exit('字体文件:'.$ttf.'不存在!');
}
$this-imgyesno();
exit('图片文件:'.$img.'不存在');
private function imgyesno(){
$this-img_info =getimagesize($this-image);
$this-img_width =$this-img_info[0];//图片宽
$this-img_height=$this-img_info[1];//图片高
//检测图片类型
case 1:$this-img_im = imagecreatefromgif($this-image);break;
default:exit('图片格式不支持水印');
$this-img_text();
private function img_text(){
imagealphablending($this-img_im,true);
//设定颜色
$txt_height=$this-img_text_size;
$txt_jiaodu=$this-img_jd;
$ttf_im=imagettfbbox($txt_height,$txt_jiaodu,$this-img_ttf,$this-img_text);
unset($ttf_im);
$txt_y =$this-img_height-$h;
$txt_x =$this-img_width-$w;
//$txt_y =0;
//$txt_x =0;
$this-img_new=@imagettftext($this-img_im,$txt_height,$txt_jiaodu,$txt_x,$txt_y,$color,$this-img_ttf,$this-img_text);
@unlink($this-image);//删除图片
case 1:imagegif($this-img_im,$this-image);break;
default: exit('水印图片失败');
//显示图片
function img_show(){echo 'img src="'.$this-image.'" border="0" alt="'.$this-img_text.'" /';}
//释放内存
private function img_nothing(){
unset($this-img_info);
imagedestroy($this-img_im);
以上就是土嘎嘎小编为大家整理的php文本水印,php相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!