A fast image blur, based on [Stack Blur](http://incubator.quasimondo.com/processing/fast_blur_deluxe.php). It works directly on buffers, so can equally be used on the front and the back end.
npm install blurredblurredGet it:
npm install -s blurred
``js
import blur from 'blurred';
let buffer;
/*
* Do something to initialise the image buffer.
* Suppose the image buffer has width 1024, height 768.
*/
// blur the image with blur radius 12
const width = 1024;
const height = 768;
const blurRadius = 12;
blur(buffer, blurRadius, width, height);
`
Some convenience methods are provided in the browser:
`js
import { blurCanvas, blurImage, blurURL } from 'blurred/util';
const blurRadius = 14;
// Blur an image located at a URL
blurURL('http://someurl', blurRadius)
.then(image => {
// do something with the image -- the argumant is an HTMLImageElement
})
.catch(err => {
console.log('Error loading or blurring image.');
});
// Blur an image located at a url, and set the document body background
// image to the result.
// For this, pass a second argument 'url'.
blurURL('http://someurl', blurRadius, 'url')
.then(url => {
document.body.style.backgroundImage = url(${url});
})
.catch(err => {
console.log('Error loading or blurring image.');
});
// Blur an ImageElement in place
blurImage(someImageElement, blurRadius);
// Blur a region in a canvas in place.
const x = 12;
const y = 30;
const width = 46;
const height = 12;
blurCanvas(someCanvas, blurRadius, x, y, width, height);
`
API – convenience functions in the browser flag is true.Typescript
Everything is typed.Changelog
- 1.0.1 : very small bug fix. Blur height is calculated correctly.
- 2.0.0 : API changes: all browser utilities are now in
blurred/util. lib no longer exists. The basic blur` functionAll modifications are Copyright (c) 2017 Alexander Kahle.
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.