黑松山资源网 Design By www.paidiu.com
本文实例讲述了PHP开发的文字水印,缩略图,图片水印实现类与用法。分享给大家供大家参考,具体如下:
1.实现类ImageToTest.class.php参考代码
class ImageToTest { /** * 图片的基本信息 */ private $info; private $image; public function __construct($src){ $info = getimagesize($src); $this->info = array( 'width'=> $info[0], 'height'=> $info[1], 'type'=> image_type_to_extension($info[2],false), 'mime'=>$info['mime'] ); $fun = "imagecreatefrom{$this->info['type']}"; $this->image = $fun($src); } /** * 操作图片 (压缩) */ public function thumb($width,$height){ $image_thumb = imagecreatetruecolor($width,$height); imagecopyresampled($image_thumb,$this->image,0,0,0,0,$width,$height, $this->info['width'],$this->info['height']); imagedestroy($this->image); $this->image = $image_thumb; } /** * 操作图片(添加文字水印) */ public function fontMark($content,$font_url,$size,$color,$local,$angle){ $col = imagecolorallocatealpha($this->image,$color[0],$color[1],$color[2],$color[3]); imagettftext($this->image,$size,$angle,$local['x'],$local['y'],$col,$font_url,$content); } /** * 操作图片(添加水印图片) */ public function imageMark($source,$local,$alpha){ //1.获取水印图片的基本信息 $info2 = getimagesize($source); //2.通过水印的图片编号来获取水印的图片类型 $type2 = image_type_to_extension($info2[2],false); //3.在内存中创建一个和我们的水印图像一致的图像类型 $func2 = "imagecreatefrom{$type2}"; //4.把水印图片复制到内存中 $water = $func2($source); //5.合并图片 imagecopymerge($this->image,$water,$local['x'],$local['y'],0,0,$info2[0],$info2[1],$alpha); //6.销毁水印图片 imagedestroy($water); } /** * 在浏览器中输出图片 */ public function show(){ header("Content-type:".$this->info['mime']); $funs = "image{$this->info['type']}"; $funs($this->image); } /** * 把图片保存到硬盘里 */ public function save($newName){ $funs = "image{$this->info['type']}"; $funs($this->image,'./outPut/'.$newName.'.'.$this->info['type']); } /** * 销毁图片 使用析构函数 */ public function __destruct() { imagedestroy($this->image); } }
2.测试参考代码
require_once('ImageToTest.class.php'); /*$src = './image/wbg.jpg'; $image = new ImageToTest($src); $image->thumb(700,550); $image->show();*/ /*$src2 = './image/wbg.jpg'; $content = 'SGC'; $font_url = './image/YGYcuhei.ttf'; $size = 33; $color = array( 0=>2, 1=>222, 2=>222, 3=>60 ); $local = array( 'x'=>20, 'y'=>100 ); $angle = 10; $image2 = new ImageToTest($src2); $image2->fontMark($content,$font_url,$size,$color,$local,$angle); $image2->show(); $image2->save('hahahah');*/ $src3 = './image/wbg.jpg'; $source = './image/water.jpg'; $local = array( 'x'=>20, 'y'=>100 ); $font_url = './image/YGYcuhei.ttf'; $size = 38; $color = array( 0=>2, 1=>222, 2=>222, 3=>60 ); $alpha = 60; $angle = 50; $image3 = new ImageToTest($src3); $image3->imageMark($source,$local,$alpha); $image3->thumb(700,550); $image3->fontMark('Hello',$font_url,$size,$color,$local,$angle); $image3->show(); $image3->save('WAWAWAWAWA');
更多关于PHP相关内容感兴趣的读者可查看本站专题:《PHP图形与图片操作技巧汇总》、《PHP数组(Array)操作技巧大全》、《PHP数据结构与算法教程》、《php程序设计算法总结》、《PHP数学运算技巧总结》、《php字符串(string)用法总结》及《php常见数据库操作技巧汇总》
希望本文所述对大家PHP程序设计有所帮助。
黑松山资源网 Design By www.paidiu.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
黑松山资源网 Design By www.paidiu.com
暂无评论...
P70系列延期,华为新旗舰将在下月发布
3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。
而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?
根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。
更新日志
2025年03月06日
2025年03月06日
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]