学习使用php实现生成模糊图片的方法类整理
学习使用php实现生成模糊图片的方法类整理
<?phpclass image_blur
{/*** 图片高斯模糊(适用于png/jpg/gif格式)* @param $srcImg 原图片* @param $savepath 保存路径* @param $savename 保存名字* @param $positon 模糊程度* @blurFactor的值代表模糊程度*基于Martijn Frazer代码的扩充, 感谢 Martijn Frazer*/public function gaussian_blur($srcImg, $savepath = null, $savename = null, $blurFactor = 3){$gdImageResource = $this->image_create_from_ext($srcImg);$srcImgObj = $this->blur($gdImageResource, $blurFactor);$temp = pathinfo($srcImg);$name = $temp['basename'];$path = $temp['dirname'];$exte = $temp['extension'];$savename = $savename ? $savename : $name;$savepath = $savepath ? $savepath : $path;$savefile = $savepath . '/' . $savename;$srcinfo = @getimagesize($srcImg);switch ($srcinfo[2]) {case 1:imagegif($srcImgObj, $savefile);break;case 2:imagejpeg($srcImgObj, $savefile);break;case 3:imagepng($srcImgObj, $savefile);break;default:return '保存失败'; //保存失败}return $savefile;imagedestroy($srcImgObj);}/*** Strong Blur** @param $gdImageResource 图片资源* @param $blurFactor 可选择的模糊程度* 可选择的模糊程度 0使用 3默认 超过5时 极其模糊* @return GD image 图片资源类型* @author Martijn Frazer, idea based on http://stackoverflow.com/a/20264482*/private function blur($gdImageResource, $blurFactor = 3){// blurFactor has to be an integer$blurFactor = round($blurFactor);$originalWidth = imagesx($gdImageResource);$originalHeight = imagesy($gdImageResource);$smallestWidth = ceil($originalWidth * pow(0.5, $blurFactor));$smallestHeight = ceil($originalHeight * pow(0.5, $blurFactor));// for the first run, the previous image is the original input$prevImage = $gdImageResource;$prevWidth = $originalWidth;$prevHeight = $originalHeight;// scale way down and gradually scale back up, blurring all the wayfor ($i = 0; $i < $blurFactor; $i += 1) {// determine dimensions of next image$nextWidth = $smallestWidth * pow(2, $i);$nextHeight = $smallestHeight * pow(2, $i);// resize previous image to next size$nextImage = imagecreatetruecolor($nextWidth, $nextHeight);imagecopyresized($nextImage, $prevImage, 0, 0, 0, 0,$nextWidth, $nextHeight, $prevWidth, $prevHeight);// apply blur filterimagefilter($nextImage, IMG_FILTER_GAUSSIAN_BLUR);// now the new image becomes the previous image for the next step$prevImage = $nextImage;$prevWidth = $nextWidth;$prevHeight = $nextHeight;}// scale back to original size and blur one more timeimagecopyresized($gdImageResource, $nextImage,0, 0, 0, 0, $originalWidth, $originalHeight, $nextWidth, $nextHeight);imagefilter($gdImageResource, IMG_FILTER_GAUSSIAN_BLUR);// clean upimagedestroy($prevImage);// return resultreturn $gdImageResource;}private function image_create_from_ext($imgfile){$info = getimagesize($imgfile);$im = null;switch ($info[2]) {case 1:$im = imagecreatefromgif($imgfile);break;case 2:$im = imagecreatefromjpeg($imgfile);break;case 3:$im = imagecreatefrompng($imgfile);break;}return $im;}}$image_blur = new image_blur();$image_blur->gaussian_blur("./wenku_pic.jpg", null, 'wenku_pic_mohu.jpg', 3);?>
原图效果:
生成模糊图片后的效果:
学习使用php实现生成模糊图片的方法类整理相关推荐
- python在线学习pdf_扣丁学堂Python在线学习之将pdf转成图片的方法
扣丁学堂Python在线学习之将pdf转成图片的方法 2018-05-23 11:29:01 1266浏览 Python将pdf转成图片的方法,不论是参加 本篇文章记录如何使用python将pdf文件 ...
- python生成圆形_python生成圆形图片的方法
本文实例为大家分享了python生成圆形图片的具体代码,供大家参考,具体内容如下 # -*- coding: utf-8 -*- """ __author__= 'Du' ...
- python生成一个圆_python生成圆形图片的方法
本文实例为大家分享了python生成圆形图片的具体代码,供大家参考,具体内容如下 # -*- coding: utf-8 -*- """ __author__= 'Du' ...
- Java生成随机图片验证码工具类
一.第一种生成随机图片验证码 public class VerifyCodeUtil {//生成随机数据的数据源 public static final String VERIFY_CODES = & ...
- php 生成模糊图片
<?php class image_blur{/*** 图片高斯模糊(适用于png/jpg/gif格式)* @param $srcImg 原图片* @param $savepath 保存路径* ...
- 多张图片如何合成gif?在线生成gif图片的方法
图片已经成为我们日常生活工作的必需品了,图片的格式也有很多种,比如最常见的图片格式有jpg.png以及gif.其中,gif格式的动图相比于其他两种格式的图片内容展示的更多.那么,这种gif格式的图片我 ...
- C#实现将Chart图表生成JPG图片的方法
SaveFileDialog savefile= new SaveFileDialog(); savefile.Filter = "JPEG文件|*.jpg" ...
- 使用pillow生成分享图片
重复性的工作一定要交给计算机去做! 有时候要为公司做一张宣传用的分享图片,很简单交给设计通过ps.AI做好就行了,但是如果一个网站要为每个用户生成一张专属的分享图片,如果让设计师一张一张的去做,哪设计 ...
- Photoshop根据图片模板批量生成动态图片
需求:给定图片模板,在图片上面维护相关数据,把Excel表中的信息一个一个作到图中. 就技术角度而言,这样的操作并没有多少技术含量,然而却需要耗费大量的时间.如果提供的数据是上百条甚至上千条,你是否仍 ...
最新文章
- 41岁程序员被裁,北京有1500万房产,程序员:我该不该退休?
- useGeneratedKeys的详解
- python的pillow给图片加文字_Python-Pillow库给图片添加文字、水印
- CVPR 2021 | 姿态可控的语音驱动
- Mathematica 13 for Mac(科学计算软件)
- matlab删掉txt文件中的数据,matlab中读取txt数据文件(txt文本文档)
- WOL(Wake-On-LAN)网络唤醒介绍
- 腾讯 云通信 如何启动Demo
- heima并发30---ConcurrentHashMap--274(143-149)
- ES系列-- ILM索引生命周期管理
- 20145325张梓靖 《网络对抗技术》 Web安全基础实践
- 高刷新率笔记本电脑将低刷新率显示器作为扩展屏
- 空间计量 python_空间计量经济学与Stata实现
- Microsoft公司 .CAB文件格式
- 【BZOJ-1194】潘多拉的盒子 拓扑排序 + DP
- Google(谷歌)拼音输入法发布
- Matlab--k-means聚类算法实现
- 调光调色带人体感应台灯方案-DLT8SA20A-杰力科创
- 使用VB6资源文件开发多国语言应用攻略
- 无法通过微软正版验证怎么办?
热门文章
- 【定位问题】基于RSSI均值的等边三角形定位算法matlab系统
- springboot 应用:异常管理,应用启动过程,应用监控 Prometheus 和 Grafana
- 看到别人比自己优秀,为何会难受?
- 各版本Qt下载传送门
- laravel-admin Model does not exists添加模型报错
- 内核参数tcp_tw_reuse=2,对高并发的服务有影响吗?
- ttlink无线打印服务器,TTLINK TT-180U1打印机服务器 TCP/IP添加打印机的教程
- 微信小程序app.json全局配置项
- php 随即英文,PHP生成随机英文用户名
- 任天堂Switch便携底座方案