php图片加水印保存(php水印生成源码)

华为云服务器特价优惠火热进行中!

2核2G2兆仅需 38 元;4核4G3兆仅需 79 元。购买时间越长越优惠!更多配置及优惠价格请咨询客服。

合作流程:
1、点击链接注册/关联华为云账号:点击跳转
2、添加客服微信号:cloud7591,确定产品方案、价格方案、服务支持方案等;
3、客服协助购买,并拉微信技术服务群,享受一对一免费技术支持服务;
技术专家在金蝶、华为、腾讯原厂有多年工作经验,并已从事云计算服务8年,可对域名、备案、网站搭建、系统部署、AI人工智能、云资源规划等上云常见问题提供更专业靠谱的服务,对相应产品提供更优惠的报价和方案,欢迎咨询。

本篇文章给大家谈谈php图片加水印保存,以及php水印生成源码对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

微信号:cloud7591
如需了解更多,欢迎添加客服微信咨询。
复制微信号

本文目录一览:

php 给图片添加文字或图片 并实现保存,,急救!!

简单说,这就是PHP的一个生成水印的功能了。

直乱念接帖代码给你。并附上注释吧,应该能看懂。

?php

header("Content-type: image/jpeg");    //浏览器输出,如不需要可去掉此行

$im = @imagecreatefromjpeg('test.jpg');    //从图片建立文件差烂,此处以jpg文件格式为例

$white = imagecolorallocate($im, 255, 255, 255);

$grey = imagecolorallocate($im, 128, 128, 128);

$black = imagecolorallocate($im, 0, 0, 哗庆困0);

$text = 'Testing...'; //要写到图上的文字

$font = 'arial.ttf'; //写的文字用到的字体。

$srcw=imagesx($im);

imagettftext($im, 20, 0, $srcw-210, 21, $grey, $font, $text);

imagettftext($im, 20, 0, 10, 20, $black, $font, $text);

imagettftext($im, 20, 0, 9, 19, $white, $font, $text);

imagepng($im);

imagedestroy($im);

?

PHP执行FTP 上传 加水印问题

这个不管你加不加水印,图片都是先上传到你键裤的服务器的缓存,再上传到FTP,加誉告水稿虚简印是中间那里再加个使用GD库处理一下图片

imagefttext生成水印怎么保存 php的

/*打开图片*/

1配置图片路径(就是你想要操作的图片的路径)

2获取图片信息(通过GD库的方法,得到你想要处理的图片的基本信息)

3通过图像的编码来获卖核哗取图像的类型

4在内存中创建一个和我们图片类型一样的图像

5把图片复制到内存中

/*操作图片*/

1设置字体路径

2填写我们水印的内容

3设置字体的的颜色和透明度

4将字体向图片写入文字

/*输出图片*/

1浏览器输出

2保存图片

/*销中行毁图片*/

?php

$src="img/Porsche-911.jpg";

$info=getimagesize($src);

$type=image_type_to_extension($info[2],false);

$fun="imagecreatefrom{$type}";// $fun=imagecreatefromjpeg; $fun=imagecreatefrompng

$image=$fun($src);

$font="fonts/MSYHL.TTC";

$content="你好,NeiVan";

$color=imagecolorallocatealpha($image,255,255,255,50);

imagettftext($image, 20, 0, 100, 50, $color, $font, $content);

header('content-type:'.$info['mime']);

$func="image{$type}"; //imagejpeg imagepng 氏帆imagegif

$func($image);

$func($image,'newimage'.$type);

imagedestroy($image);

?

谁有能用的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,$jiaodu=0){

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();

}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_jiaodu=$this-img_jd;

$ttf_im=imagettfbbox($txt_height,$txt_jiaodu,$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_jiaodu,$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 怎么打开一个存在的图片再加水印?

这个虽亏模链然可以实现.在载入的时候加上水印.

但是你考虑过么.这样每次打开的销孙时候都会加水印.

一个是图片会一直变化.直到很码启难看.

另外一个是,每次都执行.速度将变慢.

我这有个已经实现了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);

}

imagecopyresized($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);

imagecopy($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);

imagecopyresampled($newImg,$img,0,0,$x,$y,$width,$height,$width,$height);

return $this-createNewImage($newImg, $pre.$name, $imgInfo);

}

}

php图片加水印保存的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于php水印生成源码、php图片加水印保存的信息别忘了在本站进行查找喔。

发布于 2023-04-14 08:04:20
收藏
分享
海报
47
目录

    忘记密码?

    图形验证码

    复制成功
    微信号: cloud7591
    如需了解更多,欢迎添加客服微信咨询。
    我知道了