A lightweight TypeScript library to detect if an image is blurry using Laplacian variance analysis.
npm install is-image-blurryimport isImageBlurry from 'is-image-blurry';
// Basic usage with default threshold (400)
const isBlurry = await isImageBlurry({ dataUrl: 'data:image/jpeg;base64,...' });
// Custom threshold (lower values = more sensitive to blur)
const isBlurry = await isImageBlurry({
dataUrl: 'data:image/jpeg;base64,...',
threshold: 300
});Returns a Promise that resolves to true if the image is detected as blurry, false otherwise.
options.dataUrl(string): Base64 data URL of the imageoptions.threshold(number, optional): Blur detection threshold. Default: 400. Lower values make detection more sensitive.
Promise<boolean>: True if image is blurry, false otherwise
The library uses the Laplacian operator to detect edges in the image and calculates the variance of the result. Images with low variance are considered blurry as they have fewer sharp edges.
This library requires a browser environment with Canvas API support.
MIT