PHP uses Gaussian algorithm to blur images

*文
Release: 2023-03-18 22:34:01
Original
1580 people have browsed it

How to blur images in php? This article mainly introduces the use of Gaussian algorithm in PHP to realize the blur processing function of images, and analyzes the related operation skills of PHP graphics processing in the form of examples. Friends in need can refer to it. I hope to be helpful.

The details are as follows:

<?php
class image_blur{
   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[&#39;basename&#39;];
    $path = $temp[&#39;dirname&#39;];
    $exte = $temp[&#39;extension&#39;];
    $savename = $savename ? $savename : $name;
    $savepath = $savepath ? $savepath : $path;
    $savefile = $savepath .&#39;/&#39;. $savename;
    $srcinfo = @getimagesize($srcImg);
    switch ($srcinfo[2]) {
      case1: imagegif($srcImgObj, $savefile); break;
      case2: imagejpeg($srcImgObj, $savefile); break;
      case3: imagepng($srcImgObj, $savefile); break;
      default: return&#39;保存失败&#39;; //保存失败
    }
    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);
Copy after login

This method came to Baidu. Someone who interviewed me asked me to do it, and Baidu got a lot of information to implement it.

The value of blurFactor represents the degree of blur

Related recommendations:

Strong PHP image processing class

ppt picture transparency php The effect of adding transparency gradient to the picture

php Picture operation class (picture addition Watermark)

The above is the detailed content of PHP uses Gaussian algorithm to blur images. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!