[RFC] add radius and sigma to IMG_FILTER_GAUSSIAN_BLUR
| From: | Felix Niklas | Date: | Wed, 28 Sep 2016 08:09:54 +0000 |
| Subject: | [RFC] add radius and sigma to IMG_FILTER_GAUSSIAN_BLUR | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-96173@lists.php.net to get a copy of this message | ||
Hey there,
this is my first time on here and I want to start out by saying how thankful I am for your work.
Thank you for working on php. Thank you for pushing this language further.
tl;dr: I’d like to add the parameters radius and sigma to the $filtertype IMG_FILTER_GAUSSIAN_BLUR
by switching the underlying libgd method from <gdImageGaussianBlur> (accepts no parameters) to
<gdImageCopyGaussianBlurred> (accepts these parameters).
Recently I wanted to replace a css blur filter with pre-processed images that get blurred on the
server in order to improve the scroll-performance in the browser. I had to realise that
imagefilter’s IMG_FILTER_GAUSSIAN_BLUR is not suitable for the job. It maps to
<gdImageGaussianBlur>. This method lacks the radius and sigma parameters. Instead it
“performs a Gaussian blur of radius 1 on the image” [1]. Imagine using a brush to blur an image:
radius 1 is like using a tiny tiny brush. What would you use to blur more intensely? A big brush.
But the option to switch is not there. SimpleImage.php tries to overcome this by blurring with the
tiny brush over and over [2]. The thing is – the tiny brush is inevective. If you want a big blur
you need a big brush. And it can be achieved by binding to <gdImageCopyGaussianBlurred>
instead of <gdImageGaussianBlur>.
I think I can write the patch for the method [3]. The added parameters would have to get checked so
I’d have to look into how <zend_parse_parameters> works. <gdImageGaussianBlur> returns
a boolean, <gdImageCopyGaussianBlurred> [4] returns a copy of the image instead. If
<gdImageCopyGaussianBlurred> fails it returns NULL. So the code handling the return value
would have to handle a NULL return instead of an integer > 0 return.
Thoughts?
–Felix
[1] gd_filter.c <gdImageGaussianBlur> https://github.com/libgd/libgd/blob/master/src/gd_filter.c#L709
[2] SimpleImage.php <blur> https://github.com/claviska/SimpleImage/blob/master/src/abeautifulsite/SimpleImage.php#L174
[3] gd.c <php_image_filter_gaussian_blur> https://github.com/php/php-src/blob/master/ext/gd/gd.c#L4392
[4] gd_filter.c <gdImageCopyGaussianBlurred> https://github.com/libgd/libgd/blob/master/src/gd_filter.c#L922