图片加水印php
Ⅰ php如何根据图片色阶不同添加水印
在使用php编程的时候, 很多时候需要对上传的图片加水印,来确定图片版权和出处. 但是,一般情况下加水印的位置是图片的右下角, 但是,不同图片的色阶不同,有时候我们 图片的水印和图片本身色阶相同,就会造成水印不明显.
下面这段代码可以实现自动识别图片的色阶,更加色阶差来添加图片的水印,这样可以避免水印和图片色阶一样的弊端.
<?php
function add_wm($nmw_water, $src_file, $output_file, $x, $y) {
if(file_exists($output_file))
return;
$w1 = MagickGetImageWidth($nmw_water);
$h1 = MagickGetImageHeight($nmw_water);
$nmw =NewMagickWand();
MagickReadImage($nmw, $src_file);
// 默认的加水印位置调整
$lt_w = 50;
$lt_h = 50;
if($x == 0){
$w = MagickGetImageWidth($nmw);
$h = MagickGetImageHeight($nmw);
$x = $w;
$y = $h;
}else{
// 根据具体情况调整
$lt_w = 30;
$lt_h = 40;
}
MagickCompositeImage($nmw, $nmw_water, MW_OverCompositeOp, $x - $w1 - $lt_w, $y - $h1 - $lt_h);
MagickWriteImage($nmw, $output_file);
DestroyMagickWand($nmw);
}
// 还是groovy的eachFileRecurse好用啊
function add_wm_recurse($nmw_water, $to_dir, $output_dir, $arr) {
$dp = dir($to_dir);
while($file=$dp->read()){
if($file != '.' && $file != '..'){
if(is_dir($to_dir . '/' . $file)){
mkdir($output_dir . '/' . $file);
add_wm_recurse($nmw_water, $to_dir . '/' . $file, $output_dir . '/' . $file, $arr);
}else{
if(!array_key_exists($to_dir . '/' . $file, $arr)){
continue;
}
$sub_arr = $arr[$to_dir . '/' . $file];
if($sub_arr){
$x = intval($sub_arr[0]);
$y = intval($sub_arr[1]);
add_wm($nmw_water, $to_dir . '/' . $file, $output_dir . '/' . $file, $x, $y);
}
}
}
}
$dp->close();
}
$to_dir = './resized';
$output_dir = './output';
// 这个是我用java的ImageIO遍历图片像素获取的符合裤子颜色的区域的坐标array(posX, posY)
$arr = array(
array(50, 50)
);
$water = './water.png';
$nmw_water =NewMagickWand();
MagickReadImage($nmw_water, $water);
add_wm_recurse($nmw_water, $to_dir, $output_dir, $arr);
DestroyMagickWand($nmw_water);
?>
补充:
PHP图像处理模块 MagickWand用法
MagickWand 是一个PHP的模块,用来访问 ImageMagick 的图像处理库。下面是一个使用 MagicWand 的代码片段:
$magick_wand=NewMagickWand();
MagickReadImage($magick_wand,'rose.jpg');
$drawing_wand=NewDrawingWand();
DrawSetFont($drawing_wand,"/usr/share/fonts/bitstream-vera/Vera.ttf");
DrawSetFontSize($drawing_wand,20);
DrawSetGravity($drawing_wand,MW_CenterGravity);
$pixel_wand=NewPixelWand();
PixelSetColor($pixel_wand,"white");
DrawSetFillColor($drawing_wand,$pixel_wand);
if (MagickAnnotateImage($magick_wand,$drawing_wand,0,0,0,"Rose") != 0)
{
MagickEchoImageBlob( $magick_wand );
}
else
{
echo MagickGetExceptionString($magick_wand);
}
?>
安装方法:
1. 下载 php_magickwand_q16_st.dll for 5.2.x
2. 将其放在PHP的扩展目录
3. 在php.ini文件总增加 extension=php_magickwand_q16_st.dll
4. 重新启动apache
Ⅱ php图片加水印出错
代码没迅升睁有问题。
运行时报错的原因是在执行header("Content-Type....")之前有echo或者输出了笑念什么东西。
修改方法是删除header()之前的所有输出。
BTW,你看报错中提到的header是亩岁第11行,所以你给出的代码之前应该还有点什么东西吧。检查一下吧。
Ⅲ php如何给图片加文字水印
我知道的有三种,都是使用GD库的image函数
一种是直接在图片上写文字
imagefttext();
一种是带透明度的水印图片
image();
还有一种是可以自定义水印图片透明度的
imagemerge();
你想要什么效果,可以接着细说
Ⅳ php图片水印代码问题拜托了各位 谢谢
不显示的话就是你没输出来,请参考以下代码重新检查一遍: ------------------------------华丽分割线------------------------------------- <? /* * 功能:PHP图片水印 (水印支持图片或文字) * 参数: * $groundImage 背景图片,即需要加水印的图片,暂只支持GIF,JPG,PNG格式; * $waterPos 水印位置,有10种状态,0为随机位置; * 1为顶端居左,2为顶端居中,3为顶端居右; * 4为中部居左,5为中部居中,6为中部居右; * 7为底端居左,8为底端居中,9为底端居右; * $waterImage 图片水印,即作为水印的图片,暂只支持GIF,JPG,PNG格式; * $waterText 文字水印,即把文字作为为水印,支持ASCII码,不支持中文; * $fontSize 文字大小,值为1、2、3、4或5,默认为5; * $textColor 文字颜色,值为十六进制颜色值,默认为#CCCCCC(白灰色); * $fontfile ttf字体文件,即用来设置文字水印的字体。使用windows的用户在系统盘的目录中 * 搜索*.ttf可以得到系统中安装的字体文件,将所要的文件拷到网站合适的目录中, * 默认是当前目录下arial.ttf。 * $xOffset 水平偏移量,即在默认水印坐标值基础上加上这个值,默认为0,如果你想留给水印留 * 出水平方向上的边距,可以设置这个值,如:2 则表示在默认的基础上向右移2个单位,-2 表示向左移两单位 * $yOffset 垂直偏移量,即在默认水印坐标值基础上加上这个值,默认为0,如果你想留给水印留 * 出垂直方向上的边距,可以设置这个值,如:2 则表示在默认的基础上向下移2个单位,-2 表示向上移两单位 * 返回值: * 0 水印成功 * 1 水印图片格式目前不支持 * 2 要水印的背景图片不存在 * 3 需要加水印的图片的长度或宽度比水印图片或文字区域还小,无法生成水印 * 4 字体文件不存在 * 5 水印文字颜色格式不正确 * 6 水印背景图片格式目前不支持 * 修改记录: * * 注意:Support GD 2.0,Support FreeType、GIF Read、GIF Create、JPG 、PNG * $waterImage 和 $waterText 最好不要同时使用,选其中之一即可,优先使用 $waterImage。 * 当$waterImage有效时,参数$waterString、$stringFont、$stringColor均不生效。 * 加水印后的图片的文件名和 $groundImage 一样。 * 作者:高西林 * 日期:2007-4-28 * 说明:本程序根据longware的程序改写而成。 */ function imageWaterMark($groundImage,$waterPos=0,$waterImage="",$waterText="",$fontSize=12,$textColor="#CCCCCC", $fontfile='./arial.ttf',$xOffset=0,$yOffset=0) { $isWaterImage = FALSE; //读取水印文件 if(!empty($waterImage) && file_exists($waterImage)) { $isWaterImage = TRUE; $water_info = getimagesize($waterImage); $water_w = $water_info[0];//取得水印图片的宽 $water_h = $water_info[1];//取得水印图片的高 switch($water_info[2]) { //取得水印图片的格式 case 1:$water_im = imagecreatefromgif($waterImage);break; case 2:$water_im = imagecreatefromjpeg($waterImage);break; case 3:$water_im = imagecreatefrompng($waterImage);break; default:return 1; } } //读取背景图片 if(!empty($groundImage) && file_exists($groundImage)) { $ground_info = getimagesize($groundImage); $ground_w = $ground_info[0];//取得背景图片的宽 $ground_h = $ground_info[1];//取得背景图片的高 switch($ground_info[2]) { //取得背景图片的格式 case 1:$ground_im = imagecreatefromgif($groundImage);break; case 2:$ground_im = imagecreatefromjpeg($groundImage);break; case 3:$ground_im = imagecreatefrompng($groundImage);break; default:return 1; } } else { return 2; } //水印位置 if($isWaterImage) { //图片水印 $w = $water_w; $h = $water_h; $label = "图片的"; } else { //文字水印 if(!file_exists($fontfile))return 4; $temp = imagettfbbox($fontSize,0,$fontfile,$waterText);//取得使用 TrueType 字体的文本的范围 $w = $temp[2] - $temp[6]; $h = $temp[3] - $temp[7]; unset($temp); } if( ($ground_w < $w) || ($ground_h < $h) ) { return 3; } switch($waterPos) { case 0://随机 $posX = rand(0,($ground_w - $w)); $posY = rand(0,($ground_h - $h)); break; case 1://1为顶端居左 $posX = 0; $posY = 0; break; case 2://2为顶端居中 $posX = ($ground_w - $w) / 2; $posY = 0; break; case 3://3为顶端居右 $posX = $ground_w - $w; $posY = 0; break; case 4://4为中部居左 $posX = 0; $posY = ($ground_h - $h) / 2; break; case 5://5为中部居中 $posX = ($ground_w - $w) / 2; $posY = ($ground_h - $h) / 2; break; case 6://6为中部居右 $posX = $ground_w - $w; $posY = ($ground_h - $h) / 2; break; case 7://7为底端居左 $posX = 0; $posY = $ground_h - $h; break; case 8://8为底端居中 $posX = ($ground_w - $w) / 2; $posY = $ground_h - $h; break; case 9://9为底端居右 $posX = $ground_w - $w; $posY = $ground_h - $h; break; default://随机 $posX = rand(0,($ground_w - $w)); $posY = rand(0,($ground_h - $h)); break; } //设定图像的混色模式 imagealphablending($ground_im, true); if($isWaterImage) { //图片水印 image($ground_im, $water_im, $posX + $xOffset, $posY + $yOffset, 0, 0, $water_w,$water_h);//拷贝水印到目标文件 } else {//文字水印 if( !empty($textColor) && (strlen($textColor)==7) ) { $R = hexdec(substr($textColor,1,2)); $G = hexdec(substr($textColor,3,2)); $B = hexdec(substr($textColor,5)); } else { return 5; } imagettftext ( $ground_im, $fontSize, 0, $posX + $xOffset, $posY + $h + $yOffset, imagecolorallocate($ground_im, $R, $G, $B), $fontfile, $waterText); } //生成水印后的图片 @unlink($groundImage); switch($ground_info[2]) {//取得背景图片的格式 case 1:imagegif($ground_im,$groundImage);break; case 2:imagejpeg($ground_im,$groundImage);break; case 3:imagepng($ground_im,$groundImage);break; default: return 6; } //释放内存 if(isset($water_info)) unset($water_info); if(isset($water_im)) imagedestroy($water_im); unset($ground_info); imagedestroy($ground_im); // return 0; } ?> <?php ////////////////////// if(isset($_POST['submit'])) { if(isset($_FILES) && !empty($_FILES['userfile']) && $_FILES['userfile']['size']>0) { $uploadfile = "./".time()."_".$_FILES['userfile']['name']; if (($_FILES['userfile']['tmp_name'], $uploadfile)) { if($_POST['watertype'] == 0) { $msg = "returnvalue=".imageWaterMark($uploadfile,$_POST['waterpos'],"",$_POST['watercontent'],$_POST['fontsize'],$_POST['fontcolor'],$_POST['fontfile'],$_POST['xoffset'],$_POST['yoffset']); } else { $msg = "returnvalue=".imageWaterMark($uploadfile,$_POST['waterpos'],$_POST['watercontent']); } echo "<img src=\"".$uploadfile."\" border=\"0\">"; } else { $msg = "Fail!"; } } } ?> <html> <head> <meta http-equiv=content-type content="text/html; charset=utf-8"> <title>水印函数测试</title> </head> <body> <form enctype="multipart/form-data" method="POST"> <table> <tr> <td><input name="watertype" type="radio" value=0 checked>文字水印<input type="radio" name="watertype" value=1>水印图片</td> </tr> <tr> <td><input name="watercontent" value="blog.csdn.net/alin0725">水印文字内容或水印图片文件名</td> </tr> <tr> <td><input name="fontcolor" value="#CCCCCC">文字水印颜色</td> </tr> <tr> <td><input name="fontsize" value="10">文字字体大小</td> </tr> <tr> <td><input name="fontfile" value="./arial.ttf">文字字体文件ttf格式</td> </tr> <tr> <td>水印位置<input name="waterpos" value=0> 0为随机,其他位置值如下: <table> <tr> <td>1</td> <td>2</td> <td>3</td> </tr> <tr> <td>4</td> <td>5</td> <td>6</td> </tr> <tr> <td>7</td> <td>8</td> <td>9</td> </tr> </table> </td> </tr> <tr> <td>x方向上的偏移量<input name="xoffset" value=0>y方向上的偏移量<input name="yoffset" value=0> </td> <tr> <tr> <td>背景图片: <input name="userfile" type="file"> </td> </tr> <tr> <td><input type="submit" name="submit" value="提交"></td> </tr> <tr> <td>消息:<?php echo $msg; ?></td> </tr> </table> </form> </body> </html>
Ⅳ 谁有php批量处理图片、图片生成缩略图、图片添加水印的函数
//批量处理图片、图片生成缩略图、图片添加水印
$dir=opendir(dirname(__FILE__));
while(!!$_file=readdir($dir)){
list($filesname,$kzm)=explode(".",$_file);//获取扩展名
if($kzm=="gif"or$kzm=="jpg"or$kzm=="JPG"or$kzm=="png"){
if(!makethumb("$_file","120","120","100")){
echo'执行成功!';
}else{
echo'执行失败!';
}
}
}
closedir($dir);
/**
*处理缩略图并添加水印函数
*@accesspubliuc
*@param$srcFile-----------图片文件名
*@param$dstFile-----------另存的文件名
*@param$dstW-------------图片保存的宽度
*@param$dstH--------------图片保存的高度
*@param$rate---------------图片保存的品质
*@param$markwords-----水印文字
*@param$markimage-----水印图片
*@param使用方法makethumb("a.jpg","b.jpg","120","120","100");
*/
functionmakethumb($srcFile/*,$dstFile*/,$dstW,$dstH,$rate=100/*,$markwords=null,$markimage=null*/){
$data=GetImageSize($srcFile);
switch($data[2]){
case1:
$im=@ImageCreateFromGIF($srcFile);
break;
case2:
$im=@ImageCreateFromJPEG($srcFile);
break;
case3:
$im=@ImageCreateFromPNG($srcFile);
break;
}
if(!$im)returnFalse;
$srcW=ImageSX($im);
$srcH=ImageSY($im);
$dstX=0;
$dstY=0;
if($srcW*$dstH>$srcH*$dstW){
$fdstH=round($srcH*$dstW/$srcW);
$dstY=floor(($dstH-$fdstH)/2);
$fdstW=$dstW;
}
else
{
$fdstW=round($srcW*$dstH/$srcH);
$dstX=floor(($dstW-$fdstW)/2);
$fdstH=$dstH;
}
$ni=ImageCreateTrueColor($dstW,$dstH);
$dstX=($dstX<0)?0:$dstX;
$dstY=($dstX<0)?0:$dstY;
$dstX=($dstX>($dstW/2))?floor($dstW/2):$dstX;
$dstY=($dstY>($dstH/2))?floor($dstH/s):$dstY;
$white=ImageColorAllocate($ni,255,255,255);
$black=ImageColorAllocate($ni,0,0,0);
imagefilledrectangle($ni,0,0,$dstW,$dstH,$white);//填充背景色
ImageCopyResized($ni,$im,$dstX,$dstY,0,0,$fdstW,$fdstH,$srcW,$srcH);
//if($markwords!=null){
//$markwords=iconv("gb2312","UTF-8",$markwords);
////转换文字编码
//ImageTTFText($ni,20,30,450,560,$black,"simhei.ttf",$markwords);//写入文字水印,参数依次为,文字大小|偏转度|横坐标|纵坐标|文字颜色|文字类型|文字内容
//}elseif($markimage!=null){
//$wimage_data=GetImageSize($markimage);
//switch($wimage_data[2]){
//case1:
//$wimage=@ImageCreateFromGIF($markimage);
//break;
//case2:
//$wimage=@ImageCreateFromJPEG($markimage);
//break;
//case3:
//$wimage=@ImageCreateFromPNG($markimage);
//break;
//}
//image($ni,$wimage,500,560,0,0,88,31);//写入图片水印,水印图片大小默认为88*31
//imagedestroy($wimage);
//}
$dstFile=$srcFile.'.gif';
ImageJpeg($ni,$dstFile,$rate);
//ImageJpeg($ni,$srcFile,$rate);
imagedestroy($im);
imagedestroy($ni);
}
Ⅵ 我这有个已经实现了php上传图片的功能的类,但是现在还要给上传的每张图片加水印,请高手帮忙……
给你一个封装的图片处理的类吧!包含缩放和剪切功能!
构造方法只需要传递图片所在路径即可!对应方型敏法及参数都有注释!
请给予最佳答案!!
<?php
class Img{
private $path;
//构造方法,初始化图片信息
function __construct($path='./imgs/'){
$this->path=rtrim($path,'/').'/';
}
/**
* 对图片进行缩放
* 参数对应:文件名 缩放后宽度 缩放后高度 缩放后图片名前缀
*/
function thumb($name,$width,$height,$pre="th_"){
if(file_exists($this->path.$name)){
$imgInfo=$this->getInfo($name);
$img=$this->getImg($name,$imgInfo);
$newSize=$this->getNewSize($name,$width,$height,$imgInfo);
$newImg=$this->getNewInfo($img,$newSize,$imgInfo);
return $this->createNewImage($newImg, $pre.$name, $imgInfo);
}else{
echo '图片'.$this->path.$name.'不存在,请检查文件名及路径是否填写正确';
}
}
//辅助图片处理,获取图片的宽、高、类型属性
private function getInfo($name){
$temp=getImageSize($this->path.$name);
$imgInfo['width']=$temp[0];
$imgInfo['height']=$temp[1];
$imgInfo['type']=$temp[2];
return $imgInfo;
}
//辅助图片处理,获取创建的图片资源
private function getImg($name,$imgInfo){
$src=$this->path.$name;
switch($imgInfo['type']){
case 1:
$img=imagecreatefromgif($src);
break;
case 2:
$img=imagecreatefromjpeg($src);
break;
case 3:
$img=imagecreatefrompng($src);
break;
}
return $img;
}
//辅助图仔空片处理,获取创建的图念租瞎片资源
private function getNewSize($name,$width,$height,$imgInfo){
$newSize['width']=$imgInfo['width'];
$newSize['height']=$imgInfo['height'];
if($width<$imgInfo['width']){
$newSize['width']=$width;
}
if($height<$imgInfo['height']){
$newSize['height']=$height;
}
if($imgInfo["width"]*$newSize["width"] > $imgInfo["height"] * $newSize["height"]){
$newSize["height"]=round($imgInfo["height"]*$newSize["width"]/$imgInfo["width"]);
}else{
$newSize["width"]=round($imgInfo["width"]*$newSize["height"]/$imgInfo["height"]);
}
print_r($newSize);
return $newSize;
}
//辅助图片处理,获取缩放的图片资源
private function getNewInfo($img,$newSize,$imgInfo){
$newImg=imagecreatetruecolor($newSize['height'],$newSize['height']);
$otsc=imagecolortransparent($img);
if($otsc >=0 && $otsc <= imagecolorstotal($img)){
$tran=imagecolorsforindex($img, $otsc);
$newt=imagecolorallocate($newImg, $tran["red"], $tran["green"], $tran["blue"]);
imagefill($newImg, 0, 0, $newt);
imagecolortransparent($newImg, $newt);
}
imageresized($newImg, $img, 0, 0, 0, 0, $newSize["width"], $newSize["height"], $imgInfo["width"], $imgInfo["height"]);
imagedestroy($img);
return $newImg;
}
//辅助图片处理,创建新的图片
private function createNewImage($newImg, $newName, $imgInfo){
switch($imgInfo["type"]){
case 1://gif
$result=imageGif($newImg, $this->path.$newName);
break;
case 2://jpg
$result=imageJPEG($newImg, $this->path.$newName);
break;
case 3://png
$return=imagepng($newImg, $this->path.$newName);
break;
}
imagedestroy($newImg);
return $newName;
}
/**
* 对图片加水印
* 参数对应:需水印图片 水印图片 加水印后图片名前缀
*/
function waterMark($name,$wname,$pre="wa_"){
if(file_exists($this->path.$name)){
if(file_exists($this->path.$wname)){
$info=$this->getInfo($name);
$winfo=$this->getInfo($wname);
if($p=$this->getPosition($info,$winfo)){
$img=$this->getImg($name,$info);
$wImg=$this->getImg($wname,$winfo);
image($img, $wImg, $p["x"], $p["y"], 0, 0, $winfo["width"], $winfo["height"]);
imagedestroy($wImg);
return $this->createNewImage($img,$pre.$name,$info);
}else{
echo '水印图片尺寸大于原图片尺寸';
}
}else{
echo '水印图片'.$this->path.$wname.'不存在,请检查文件名及路径是否填写正确';
}
}else{
echo '图片'.$this->path.$name.'不存在,请检查文件名及路径是否填写正确';
}
}
//辅助图片处理,获取水印图片应处坐标
private function getPosition($info,$winfo){
if($info['width']<$winfo['width']||$info['height']<$winfo['height']){
return false;
}
$x=$info['width']-$winfo['width'];
$y=$info['height']-$winfo['height'];
return array('x'=>$x,'y'=>$y);
}
/**
* 图片剪切函数
* 对应参数:原图片 X坐标 Y坐标 宽度 高度
*/
function cut($name,$x,$y,$width,$height,$pre='cx_'){
$imgInfo=$this->getInfo($name);
$img=$this->getImg($name,$imgInfo);
$newImg=imagecreatetruecolor($width,$height);
imageresampled($newImg,$img,0,0,$x,$y,$width,$height,$width,$height);
return $this->createNewImage($newImg, $pre.$name, $imgInfo);
}
}
Ⅶ php怎么给这个图片添加日期和定位的水印
使用HTML 的Canvas画图功能,把你的原图片作为背景图,然后你根据情况在某个位置添加日期还有定位水印,然后再合成一张新的图片,生成到指定位置。希望能帮到你!
Ⅷ 谁有能用的php给图片加文字水印,最好有使用方法,注意:一定是能用的,功能强不强大另说
<?php
/*PHP图片加文字水印类库
QQ:3697578482 伤心的歌
该类库暂时只支持文字水印,位置为右下角,颜色随机
调用方法:
1、在需要加水印的文件顶部引入类库:
include_once 'imageClass.php';
2、声明新类:
$tpl=new image_fu;
3、给图片水印提供参数:
$tpl->img(图片路径,水印文字,字体路径,字体大小,字体角度);
比如:$tpl->img('abc.jpg','这是水印文字','ziti.ttf',30,0)
*/
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;
function img($img='',$txt='',$ttf='',$size=12,$jiao=0){
if(isset($img)&&file_exists($img)){//检测图片是否存在
$this->image =$img;
$this->img_text=$txt;
$this->img_text_size=$size;
$this->img_jd=$jiao;
if(file_exists($ttf)){
$this->img_ttf=$ttf;
}else{
exit('字体文件:'.$ttf.'不存在!');
}
$this->imgyesno();
}else{
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];//图片高
//检测图片类型
switch($this->img_info[2]){
case 1:$this->img_im = imagecreatefromgif($this->image);break;
case 2:$this->img_im = imagecreatefromjpeg($this->image);break;
case 3:$this->img_im = imagecreatefrompng($this->image);break;
default:exit('图片格式不支持水印');
}
$this->img_text();
}
private function img_text(){
imagealphablending($this->img_im,true);
//设定颜色
$color=imagecolorallocate($this->img_im,rand(0,255),rand(0,255),rand(0,255));
$txt_height=$this->img_text_size;
$txt_jiao=$this->img_jd;
$ttf_im=imagettfbbox($txt_height,$txt_jiao,$this->img_ttf,$this->img_text);
$w = $ttf_im[2] - $ttf_im[6];
$h = $ttf_im[3] - $ttf_im[7];
//$w = $ttf_im[7];
//$h = $ttf_im[8];
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_jiao,$txt_x,$txt_y,$color,$this->img_ttf,$this->img_text);
@unlink($this->image);//删除图片
switch($this->img_info[2]) {//取得背景图片的格式
case 1:imagegif($this->img_im,$this->image);break;
case 2:imagejpeg($this->img_im,$this->image);break;
case 3:imagepng($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中怎么给照片加水印,时间和定位地址
水印要启用gd库,如果你用框架的话按照里面调用方法就行,定位则需要第三方API服务,比如网络地图等
Ⅹ php 图片添加logo水印
imagealphablending()函数 配合 image()可达到去掉背景颜色的效果
注:水印本身必须是 透明底色的png格式
下图为实际效果图: