npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

blur-images

v0.0.2

Published

<p align="center"> <a href="https://www.npmjs.com/package/blur-images" target="_blank" rel="noopener noreferrer"> <img src="https://api.iconify.design/material-symbols:photo-library-outline-rounded.svg?color=%23ff6190" alt="logo" width='100'/></a> </p>

Downloads

11

Readme

Demo

Installation

npm i blur-images

Usage

import { blurImage } from 'blur-images';
const result = await blurImage('fixtures/brooklyn.jpg');

which outputs

{
  content: <Buffer>,
  metadata: {
    originalWidth: 1400,
    originalHeight: 350,
    width: 16,
    height: 4,
    type: 'webp',
    dataURIBase64: 'data:image/webp;base64,UklGRkIAAABXRUJQVlA4IDYAAADQAQCdASoQAAQABUB8JYgCdADjazMu8AD+flCYsVr2GH6CLYVog1jhRLpBUIu8UmqhGnoAAAA='
  }
}

How It Works

This package uses a very similar LQIP approach to the one used by Medium.

We use sharp to resize input images to a max dimension of 16px and output webp (default) or jpeg images with an encoding quality set to 20. The max dimension is a single, simple variable to tradeoff between encoded image size and visual fidelity.

This resuls in very efficient placeholder images that have noticeable artifacts due to the low quality encoding. These artifacts are then hidden in the browser using a simple blur filter.

.placeholder {
  filter: blur(20px);
  transform: scale(1.1);
}

Note that Medium uses this scale transform on its placeholder images for two reasons:

  • Hide the artifacts around the edges of the blurred images.
  • Provide an aesthetically pleasing feeling of zooming into the original image once it's loaded.

An alternative to using this blur + transform technique is to use a CSS backdrop-filter. This technique has less cross-browser support, but it produces clean blurred preview images without the need to transform the placeholder.

.placeholder::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  backdrop-filter: blur(20px);
  pointer-events: none;
}

Related

  • lqip - Original Low Quality Image Placeholders (LQIP) module.
  • sqip - Really solid SVG-based LQIP alternative.
    • See their comprehensive comparison of LQIP techniques.
    • The biggest disadvantage of this approach is that it's ~10-100x slower to compute these images.
  • blurhash - Really nice, compact placeholder images.
    • Requires non-native client-side decoding which makes it awkward and slow for browser usage.
    • Encoding speed is pretty slow (on par with sqip).
    • Under the hood, the webp format performs a similar set of transforms as the one used by blurhash.