当前位置: 首页 > news >正文

黑龙江建设网官方网站特种作业python3 网站建设

黑龙江建设网官方网站特种作业,python3 网站建设,生物医药网站建设,百度推广的优化软件我们对图片的处理主要是添加水印和等比缩放#xff0c;在PHP中#xff0c;封装一个类来实现两个功能。源代码如下#xff1a;?php/***图片处理*/ class Image {//路径private $path ./upload/;//随机文件名private $isRandName;//初始化成员方法public function __con…         我们对图片的处理主要是添加水印和等比缩放在PHP中封装一个类来实现两个功能。源代码如下?php/***图片处理*/ class Image {//路径private $path  ./upload/;//随机文件名private $isRandName;//初始化成员方法public function __construct($path  null , $r  true){if (!is_null($path)) {$this-path  rtrim($path,/)./;}$this-isRandName  $r;}//water水印的方法//源图片 $dst  目标(水印 $src)  位置(9宫格) 前缀($prefix) 透明度($tmd )public function water($dst,$src,$pos  9,$prefix  wa_, $tmd  100){//判断文件路径是否存在$src  $this-path . $src;if (!file_exists($dst) || !file_exists($src)) {exit(图片或者水印不存在);}//获取图像图片和水印的相关信息$dstInfo  self::getImageInfo($dst);$srcInfo  self::getImageInfo($src);//var_dump($dstInfo);//判断宽高是否超过了目标图片的宽高if (!$this-_checkSize($dstInfo,$srcInfo)) {exit(水印图片的宽、高不合法);}//摆放位置  1 2 3 4 5 6 7 8 9 九宫格3行3列$postion  self::getPostion($dstInfo,$srcInfo,$pos);//打开图片$dstRes  self::openImage($dst,$dstInfo);$srcRes  self::openImage($src,$srcInfo);//将两个图片合并在一起  通过两张图片信息将图片合并在一起  需要自定义一个方法$newRes  $this-_mergeImage($dstRes,$srcRes,$postion,$dstInfo,$srcInfo,$tmd);//判断是否允许随机命名【保存之前】if ($this-isRandName) {//路径 前缀 产生id .  后缀//uniqid() 获取一个带前缀、基于当前时间微秒数的唯一ID$path  $this-path.$prefix . uniqid(). . .$dstInfo[subfix];} else {//路径 前缀 文件原名$path  $this-path.$prefix . $dstInfo[basename];}//保存图片self::saveImage($newRes,$path,$dstInfo);//销毁资源p_w_picpathdestroy($dstRes);p_w_picpathdestroy($srcRes);//返回路径}//等比缩放//源图片 宽 高 前缀public function thump($dst,$width,$height,$prefix  thump_){//判断文件是否存在if (!file_exists($dst)) {exit(文件路径不存在);}//获取图像的信息  没有信息就退出$info  self::getImageInfo($dst);//得到一个新的尺寸$newSize  self::getNewSize($width,$height,$info);//打开资源$res  self::openImage($dst,$info);//等比缩放这个资源  处理gif背景变黑的问题$newRes  self::kidOfImage($res,$newSize,$info);//保存$path  $this-path.$prefix.$info[basename];self::saveImage($newRes,$path,$info);//销毁资源p_w_picpathdestroy($newRes);//返回路径return $path;}//等比缩放处理private static function kidOfImage($srcImg, $size, $imgInfo){$newImg  p_w_picpathcreatetruecolor($size[width], $size[height]);$otsc  p_w_picpathcolortransparent($srcImg);if ( $otsc  0  $otsc  p_w_picpathcolorstotal($srcImg)) {$transparentcolor  p_w_picpathcolorsforindex( $srcImg, $otsc );$newtransparentcolor  p_w_picpathcolorallocate($newImg,$transparentcolor[red],$transparentcolor[green],$transparentcolor[blue]);p_w_picpathfill( $newImg, 0, 0, $newtransparentcolor );p_w_picpathcolortransparent( $newImg, $newtransparentcolor );}p_w_picpathcopyresized( $newImg, $srcImg, 0, 0, 0, 0, $size[width], $size[height], $imgInfo[width], $imgInfo[height] );p_w_picpathdestroy($srcImg);return $newImg;}//得到一个新的尺寸private static function getNewSize($width, $height, $imgInfo){$size[width]  $imgInfo[width];   //将原图片的宽度给数组中的$size[width]$size[height]  $imgInfo[height];  //将原图片的高度给数组中的$size[height]if($width  $imgInfo[width]) {$size[width]  $width;             //缩放的宽度如果比原图小才重新设置宽度}if ($width  $imgInfo[height]) {$size[height]  $height;            //缩放的高度如果比原图小才重新设置高度}if($imgInfo[width]*$size[width]  $imgInfo[height] * $size[height]) {$size[height]  round($imgInfo[height] * $size[width] / $imgInfo[width]);} else {$size[width]  round($imgInfo[width] * $size[height] / $imgInfo[height]);}return $size;}//获取图片的相关信息public static function getImageInfo($path){$data  [];//获取图片大小$info  getp_w_picpathsize($path);//var_dump($info);//根据打印出来的信息 将键所对应的值文件的大小赋值给data的数组中$data[width]  $info[0];$data[height]  $info[1];$data[mime]  $info[mime];//获取路径  后缀 文件名信息$path  pathinfo($path);//var_dump($path);die;//根据打印出来的信息 将将键所对应的值路径和文件名赋值给data的数组中$data[basename]  $path[basename];$data[subfix]  $path[extension];return $data;}//检查图片和水印的宽高//将图片的宽高和水印的宽高进行比较private function _checkSize($dstInfo,$srcInfo){//水印的宽应该小于图片的宽度或者水印的高度应该小于图片的高度 只要其中一个不满足就不能继续if ($dstInfo[width]  $srcInfo[width] || $dstInfo[height]  $srcInfo[height]) {return false;}return true;}//位置处理public static function getPostion($dstInfo,$srcInfo,$pos){switch ($pos) {case 1:$x  0;$y  0;break;case 2:$x  ceil(($dstInfo[width] - $srcInfo[width]) / 2 );$y  0;break;case 3:$x  $dstInfo[width] - $srcInfo[width];$y  0;break;case 4:$x  0;$y  ceil(($dstInfo[height] - $srcInfo[height]) / 2 );break;case 5:$x  ceil(($dstInfo[width] - $srcInfo[width]) / 2 );$y  ceil(($dstInfo[height] - $srcInfo[height]) / 2 );break;case 6:$x  $dstInfo[width] - $srcInfo[width];$y  ceil(($dstInfo[height] - $srcInfo[height]) / 2 );break;case 7:$x  0;$y  $dstInfo[height] - $srcInfo[height];break;case 8:$x  ceil(($dstInfo[width] - $srcInfo[width]) / 2 );$y  $dstInfo[height] - $srcInfo[height];break;case 9:$x  $dstInfo[width] - $srcInfo[width];$y  $dstInfo[height] - $srcInfo[height];break;}return [x  $x ,y $y];}//打开图片//根据图片的类型打开相应的图片资源private function openImage($path,$info){switch ($info[mime]) {case p_w_picpath/png:case p_w_picpath/x-png:$res  p_w_picpathcreatefrompng($path);break;case p_w_picpath/jpeg:case p_w_picpath/jpg:case p_w_picpath/pjpeg:$res  p_w_picpathcreatefromjpeg($path);break;case p_w_picpath/gif:$res  p_w_picpathcreatefromgif($path);break;case p_w_picpath/wbmp:case p_w_picpath/bmp:$res  p_w_picpathcreatefromwbmp($path);break;}//var_dump($res);die;return $res;}//合并图片 p_w_picpathcopymerge(图片水印图片坐标x图片坐标y水印坐标x,水印坐标y,透明度)private function _mergeImage($dstRes,$srcRes,$postion,$dstInfo,$srcInfo,$tmd){p_w_picpathcopymerge($dstRes,$srcRes,$postion[x],$postion[y],0,0,$srcInfo[width],$srcInfo[height],$tmd);return $dstRes;}//保存图片处理方法//参数需要保存的图片资源保存的路径保存的信息public static function saveImage($res,$path,$info){//根据不同的图片类型选择不同的函数进行保存switch ($info[mime]) {case p_w_picpath/png:case p_w_picpath/x-png:p_w_picpathpng($res,$path);break;case p_w_picpath/jpeg:case p_w_picpath/jpg:case p_w_picpath/pjpeg:p_w_picpathjpeg($res,$path);break;case p_w_picpath/gif:p_w_picpathgif($res,$path);break;case p_w_picpath/wbmp:case p_w_picpath/bmp:p_w_picpathwbmp($res,$path);break;}} }测试代码$img  new Image(); /* $img-water(ly.png,logo.gif,3); $img-water(ly.png,logo.gif,4);*/$img-thump(ly.png,100,100,l1_); 转载于:https://blog.51cto.com/chensenlin/1855589
http://www.yutouwan.com/news/213176/

相关文章:

  • 建网站和建网页的区别wordpress仿北京时间
  • 贵阳网站建设多钱钱线上推广费用预算
  • 做网站 域名 网站 空间wordpress 访客 用户
  • 做网站怎么优化wordpress 缓慢
  • 做网站jw100商务网站是什么
  • 卫生监督 网站建设方案现在还有人做网站吗
  • 做盗版视频网站吗企业网站制作报价单
  • 能用pinduoduo做网站吗极速微网站建设cms
  • 无锡公司做网站塘沽做网站公司
  • 制作logo免费网站微网站建设开发
  • 电子商务网站建设题库及答案api快速开发平台
  • 德阳网站建设网站室内装修图片效果图
  • 怎么做超链接网站为wordpress创建一个ftp
  • 找人做网站毕业设计什么软件可以做图片设计
  • 什么是网站流量优化甜品网站策划与建设
  • 响应式网站开发实例歌曲推广平台有哪些
  • 网站制作常见问题 图片版权诚信网站费用
  • 客户网站建设wordpress注册码
  • 外贸网站建设公司信息成都网站建设yingrihe
  • 做电商网站需要会些什么条件怎样网站不用备案
  • 珠海摥园网站建设国外对旅游网站建设的现状
  • 枣强网址建站电脑网站设计页面
  • 网站尺寸大小深圳设计公司vi设计模板
  • 建设监理协会网站wordpress注册添加验证码
  • 网站锚文本使用查询手机网址大全123客户端下载
  • 秦皇岛网站推广价钱小程序开发平台哪家好
  • 网站制作cms嘉兴网站排名
  • 广州网站优化工具北京房产网官网
  • 个人建网站运营.鄂尔多斯网站网站建设
  • 搜狗站长平台打不开一个网站的首页设计ps