我知道的有三种,都是使用GD库的image函数
一种是直接在图片上写文字
imagefttext();
一种是带透明度的水印图片
imagecopy();
还有一种是可以自定义水印图片透明度的
imagecopymerge();
你想要什么效果,可以接着细说
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);
首先打开excel界面,进入excel工作区
步骤阅读
在弹出的艺术字选项列表中,选中一个艺术字,将其选中
然后就可以在文本框中输入文字信息了,比如输入涉密文字信息
END
这个要用到PHP的GD扩展,用这个扩展库可以给图片加水印.
参考一下这段代码:
/*
* 功能:PHP图片水印 (水印支持图片或文字)
* 参数:
* $groundImage 背景图片,即需要加水印的图片,暂只支持GIF,JPG,PNG格式;
* $waterPos 水印位置,有10种状态,0为随机位置;
* $waterImage 图片水印,即作为水印的图片,暂只支持GIF,JPG,PNG格式;
* $waterText 文字水印,即把文字作为为水印,支持ASCII码,不支持中文;
* $textColor 文字颜色,值为十六进制颜色值,默认为#FF0000(红色);
*
* $waterImage 和 $waterText 最好不要同时使用,选其中之一即可,优先使用 $waterImage.
* 当$waterImage有效时,参数$waterString、$stringFont、$stringColor均不生效.
* 加水印后的图片的文件名和 $groundImage 一样.
{
$isWaterImage = FALSE;
$formatMsg = "暂不支持该文件格式,请用图片处理软件将图片转换为GIF、JPG、PNG格式.";
//读取水印文件
if(!emptyempty($waterImage) file_exists($waterImage))
$isWaterImage = TRUE;
$water_info = getimagesize($waterImage);
$water_w = $water_info[0];//取得水印图片的宽
$water_h = $water_info[1];//取得水印图片的高
case 1:$water_im = imagecreatefromgif($waterImage);break;
default:die($formatMsg);
//读取背景图片
if(!emptyempty($groundImage) file_exists($groundImage))
$ground_info = getimagesize($groundImage);
$ground_w = $ground_info[0];//取得背景图片的宽
$ground_h = $ground_info[1];//取得背景图片的高
case 1:$ground_im = imagecreatefromgif($groundImage);break;
else
die("需要加水印的图片不存在!");
//水印位置
if($isWaterImage)//图片水印
$w = $water_w;
$h = $water_h;
$label = "图片的";
else//文字水印
unset($temp);
$label = "文字区域";
if( ($ground_w$w) || ($ground_h$h) )
echo "需要加水印的图片的长度或宽度比水印".$label."还小,无法生成水印!";
return;
switch($waterPos)
case 0://随机
$posX = rand(0,($ground_w - $w));
$posY = rand(0,($ground_h - $h));
break;
case 1://1为顶端居左
$posX = 0;
$posY = 0;
$posX = $ground_w - $w;
$posY = $ground_h - $h;
default://随机
//设定图像的混色模式
imagealphablending($ground_im, true);
imagecopy($ground_im, $water_im, $posX, $posY, 0, 0, $water_w,$water_h);//拷贝水印到目标文件
die("水印文字颜色格式不正确!");
imagestring ( $ground_im, $textFont, $posX, $posY, $waterText, imagecolorallocate($ground_im, $R, $G, $B));
//生成水印后的图片
@unlink($groundImage);
case 1:imagegif($ground_im,$groundImage);break;
default:die($errorMsg);
if(isset($water_info)) unset($water_info);
if(isset($water_im)) imagedestroy($water_im);
unset($ground_info);
imagedestroy($ground_im);
//—————————————————————————————
$id=$_REQUEST['id'];
$num = count($_FILES['userfile']['name']);
print_r($_FILES['userfile']);
print_r($_FILES['userfile']['name']);
echo $num;
echo "bR";
if(isset($id)){
for($i=0;$i$id;$i◆◆){
if(isset($_FILES) !emptyempty($_FILES['userfile']) $_FILES['userfile']['size']0)
$uploadfile = "./".time()."_".$_FILES['userfile'][name][$i];
echo "br";
echo $uploadfile;
if (copy($_FILES['userfile']['tmp_name'][$i], $uploadfile))
echo "OKbr";
//文字水印
//图片水印
$waterImage="logo_ok1.gif";//水印图片路径
echo "img src=\"".$uploadfile."\" border=\"0\"";
echo "Failbr";
form enctype="multipart/form-data" method="POST"
for($a=0;$a$id;$a◆◆){
echo "文件: input name=\"userfile[]\" type=\"file\"br";
input type="submit" value="上传"
/form
以上就是土嘎嘎小编为大家整理的php添加文字水印文档介绍内容相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!