• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

如何通过php 对图片局部打马赛克

php 搞代码 4年前 (2022-01-22) 22次浏览 已收录 0个评论

php 图片局部打马赛克

代码如下:

<?php/** 图片局部打马赛克* @param  String  $source 原图* @param  Stirng  $dest<p style="color:transparent">2本文来源gao!daima.com搞$代!码网</p><span>搞代gaodaima码</span>   生成的图片* @param  int     $x1     起点横坐标* @param  int     $y1     起点纵坐标* @param  int     $x2     终点横坐标* @param  int     $y2     终点纵坐标* @param  int     $deep   深度,数字越大越模糊* @return boolean*/function imageMosaics($source, $dest, $x1, $y1, $x2, $y2, $deep){    // 判断原图是否存在    if(!file_exists($source)){        return false;    }    // 获取原图信息    list($owidth, $oheight, $otype) = getimagesize($source);    // 判断区域是否超出图片    if($x1>$owidth || $x1<0 || $x2>$owidth || $x2<0 || $y1>$oheight || $y1<0 || $y2>$oheight || $y2<0){        return false;    }    switch($otype){        case 1: $source_img = imagecreatefromgif($source); break;        case 2: $source_img = imagecreatefromjpeg($source); break;        case 3: $source_img = imagecreatefrompng($source); break;        default:            return false;    }    // 打马赛克    for($x=$x1; $x<$x2; $x=$x+$deep){        for($y=$y1; $y<$y2; $y=$y+$deep){            $color = imagecolorat($source_img, $x+round($deep/2), $y+round($deep/2));            imagefilledrectangle($source_img, $x, $y, $x+$deep, $y+$deep, $color);        }    }    // 生成图片    switch($otype){        case 1: imagegif($source_img, $dest); break;        case 2: imagejpeg($source_img, $dest); break;        case 3: imagepng($source_img, $dest); break;    }    return is_file($dest)? true : false;}$source = 'source.jpg';$dest = 'dest.jpg';$flag = imageMosaics($source, $dest, 176, 98, 273, 197, 4);echo '<img src="'.$source.'">';echo '<img src="'.$dest.'">';?>

本文讲解了如何通过php 对图片局部打马赛克,更多相关内容请随时关注我们网站!

相关推荐:

如何通过php 获取文件mime类型的方法讲解

如何通过php 获取Youtube某个User所有Video信息

php 字符编码转换类的相关内容

以上就是如何通过php 对图片局部打马赛克的详细内容,更多请关注搞代码gaodaima其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:如何通过php 对图片局部打马赛克

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址