Home>Article>Backend Development> How to achieve Gaussian blur in pictures in PHP

How to achieve Gaussian blur in pictures in PHP

藏色散人
藏色散人 Original
2021-05-12 09:47:54 2873browse

In PHP, the Gaussian algorithm can be used to blur the image. The statement to implement it is "function gaussian_blur($srcImg,$savepath=null...$blurFactor=3){...}", where The value of blurFactor represents the degree of blur.

How to achieve Gaussian blur in pictures in PHP

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

The example of this article describes the use of Gaussian algorithm in PHP to realize the image processing Blur function. I would like to share it with you for your reference. The details are as follows:

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]) { case1: imagegif($srcImgObj, $savefile); break; case2: imagejpeg($srcImgObj, $savefile); break; case3: imagepng($srcImgObj, $savefile); break; default: return'保存失败'; //保存失败 } return $savefile; imagedestroy($srcImgObj); } } $image_blur = new image_blur(); //blurFactor的值代表模糊程度,savepath为空时候直接覆盖,savename为空直接用原名 $image_blur->gaussian_blur($srcImg="./5.jpg",$savepath=null,$savename=null,$blurFactor=5); ?>

This method was found on Baidu. Someone who interviewed me asked me to do it, and I needed a lot of information from Baidu to implement it.

The value of blurFactor represents the degree of blur

Effect display:

Original image:

Blurry degree 2

Blurry level 3

Blurry level 4

Blurry Level 5

Blurry Level 6

Blurry Level 7

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to achieve Gaussian blur in pictures in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn