2808 explained code solutions for 75 technologies


php-gdHow to blur image


<?php
 
$file = '/var/www/examples/heroine.png';
$im = imagecreatefrompng($file);

for ( $i = 0; $i < 20; $i++ ) {
  imagefilter($im, IMG_FILTER_GAUSSIAN_BLUR);
}

imagePng($im, '/tmp/image.png');ctrl + c
/var/www/examples/heroine.png

path to image to blur

imagecreatefrompng

creates GD image object from given PNG image

imagefilter

applies filter to image

$i < 20

we apply Gaussian filter 20 times for better blurring effect

imagePng

saves image in PNG format to the given path


How to blur image, php gd

Usage example

<?php

$file = '/var/www/examples/heroine.png';
$im = imagecreatefrompng($file);

for ( $i = 0; $i < 20; $i++ ) {
  imagefilter($im, IMG_FILTER_GAUSSIAN_BLUR);
}

imagepng($im, '/tmp/image.png');