无为清净楼资源网 Design By www.qnjia.com
封装PHP的图片水印的类,供大家参考,具体内容如下
<"width"], $waterInfo["height"], $tmp); //得到要保存图片的文件名 $newName = $this->createNewName($image,$prefix); //得到保存图片的路径,也就是文件的全路径 $newPath = rtrim($this->path,'/').'/'.$newName; //保存图片 $this->saveImage($imageRes,$newPath); //销毁资源 imagedestroy($imageRes); imagedestroy($waterRes); //返回路径 return $newPath; } //保存图像资源 protected function saveImage($imageRes,$newPath){ $func = 'image'.$this->type; //通过变量函数进行保存 $func($imageRes,$newPath); } //得到文件名函数 protected function createNewName($imagePath,$prefix){ if ($this->isRandName){ $name = $prefix.uniqid().'.'.$this->type; }else { $name = $prefix.pathinfo($imagePath)['filename'].'.'.$this->type; } return $name; } //根据位置计算水印图片的坐标 protected function getPosition($postion,$imageInfo,$waterInfo){ switch ($postion){ case 1: $x = 0; $y = 0; break; case 2: $x = ($imageInfo['width']-$waterInfo["width"])/2; $y = 0; break; case 3: $x = $imageInfo["width"]- $waterInfo["width"]; $y = 0; break; case 4: $x = 0; $y = ($imageInfo["height"]-$waterInfo["height"])/2; break; case 5: $x = ($imageInfo['width']-$waterInfo["width"])/2; $y = ($imageInfo["height"]-$waterInfo["height"])/2; break; case 6: $x = $imageInfo["width"]- $waterInfo["width"]; $y = ($imageInfo["height"]-$waterInfo["height"])/2; break; case 7: $x = 0; $y = $imageInfo['height'] - $waterInfo["height"]; break; case 8: $x = ($imageInfo['width']-$waterInfo["width"])/2; $y = $imageInfo['height'] - $waterInfo["height"]; break; case 9: $x = $imageInfo["width"]- $waterInfo["width"]; $y = $imageInfo['height'] - $waterInfo["height"]; break; case 0: $x = mt_rand(0, $imageInfo["width"]- $waterInfo["width"]); $y = mt_rand(0, $imageInfo['height'] - $waterInfo["height"]); break; } return ['x'=>$x , 'y'=>$y]; } protected function checkImage($imageInfo,$waterInfo){ if (($waterInfo['width'] > $imageInfo['width'])||($waterInfo['height'] > $imageInfo['height'])){ return false; } return true; } //静态方法。根据图片的路径得到图片的信息,宽度,高度、mime类型 static function getImageInfo($imagePath){ $info = getimagesize($imagePath); $data['width']=$info[0]; $data['height']=$info[1]; $data['mime'] = $info['mime']; return $data; } static function openAnyImage($imagePath){ //得到图像的mime类型 $mime = self::getImageInfo($imagePath)['mime']; //根据不同的mime类型打开不同的图像 switch ($mime){ case 'image/png': $image = imagecreatefrompng($imagePath); break; case 'image/gif': $image = imagecreatefromgif($imagePath); break; case 'image/jpeg': $image = imagecreatefromjpeg($imagePath); break; case 'image/wbmp': $image = imagecreatefromwbmp($imagePath); break; } return $image; } }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com
暂无评论...
更新日志
2024年09月30日
2024年09月30日
- 纪钧瀚《钢琴阅读时光 雨中书店聆听轻音乐》[FLAC/分轨][399.62MB]
- 证声音乐图书馆《走向自然 疗心爵士乐》[320K/MP3][87.4MB]
- 证声音乐图书馆《走向自然 疗心爵士乐》[FLAC/分轨][184.94MB]
- 陈慧娴.2018-Priscilla-Ism演唱会3CD(2024环球红馆40复刻系列)【环球】【WAV+CUE】
- 郑秀文.1999-我应该得到(国)【华纳】【WAV+CUE】
- 陈家慧.2011-钢琴酒吧2CD【龙吟唱片】【WAV+CUE】
- 证声音乐图书馆《雨季 蓝调吉他 Rainy Blues》[320K/MP3][45.01MB]
- 证声音乐图书馆《雨季 蓝调吉他 Rainy Blues》[FLAC/分轨][109.13MB]
- 赞多《序章》[320K/MP3][45.54MB]
- 许巍.2004-每一刻都是崭新的【步升大风】【WAV+CUE】
- 群星.2024-四方馆影视原声带【韶愔音乐】【FLAC分轨】
- 陈雷.1997-安锁咧【金圆唱片】【WAV+CUE】
- 关淑怡.2013-MY.FAVORITE.SK.3CD【环球】【WAV+CUE】
- Sweety.2006-花言乔语【丰华】【WAV+CUE】
- 李恕权.2003-回·20年全精选2CD【SONY】【WAV+CUE】