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-preview-inliner

v1.0.1

Published

Tool for process HTML files to replace img tags with an inlined, low resolution, blurred preview image which is shown instantly and fades away once the higher resolution image had finished loading.

Downloads

2

Readme

blur-preview-inliner

Tool for process HTML files to replace img tags with an inlined, low resolution, blurred preview image which is shown instantly and fades away once the higher resolution image had finished loading.

Example

With and without blur preview

Installation

You need to have Node installed to use blur-preview-inliner. If you haven't already installed it, I recommend using NVM for Macs and Linux and NVM-Windows or Nodist for Windows.

Option 1 - NPM

Install it globally with npm i -g blur-preview-inliner. Then you will be able to use it with the bpi command.

Option 2 - Git

Clone this repository git clone ...., cd into the directory and then type npm i to install the dependencies. Then you will be able to use it by running inside the folder with ./index.js. It is recommended to set up an alias bpi pointing to the index.js file.

Once installed (and alias set up in case you installed it using Git) we can type bpi in any directory to to invoke the blur-image-inliner.

bpi <filename> [resize-size] [transition-duration-in-milliseconds]

The filename argument is the only one required and is the name of the input HTML file. resize-size is the size the largest dimension of the image to be resized to. For example, if the input image dimension is 100x20, with a resize-size of 10, the blur preview image will be of size 10x2, i.e. the largest dimension gets resized to the specified size and the smaller dimension gets resized accordingly to keep the same aspect ratio. The default value for resize-size is 10. transition-duration-in-milliseconds is the duration of the blurred to sharp transition. The default value is 2000, i.e. 2 seconds.

Example

Have a look in the example folder. You will find the input file hi-res-animals.html and the blur-preview-inlined file hi-res-animals-blurview.html. You can check that you installation works by going into the example directory, deleting the file hi-res-animals-blurview.html and then recreate it wiht this command bpi hi-res-animals.html. You can also play around with the parameters, for example bpi hi-res-animals.html 20 5000 to make the blur preview images 20 pixels in size on its longest axis and the blur-to-sharp animation to have a duration of 5 seconds.

Use 1 if you just want to use the average color of the image. Otherwise values between 5-10 are recommended, obviously this depends on the source image size and other factors. Using too large values will make the inlined image too large and the preview looks more like a low resolution version of the sharp image, rather than a blurred preview.

How it works

The script scans the input HTML file for img tags. Then it extracts the src attribute of each image, it downloads the image, resizes the image and wraps the original img tag in a div alongside with the resized, inlined preview image. Because the preview image is inlined, it can be shown as soon as the HTML for it loaded. Although the inlined preview image is much smaller than the original one, we resize it to the size of the original image. The browser will smoothly resize the image, so rather than looking pixely, it looks blurry. Roughly speaking, input

<img src="http://foo.bar/qux.jpg" style="padding: 5px; width: 30%; height: auto;">

will get transformed to

<div class="blur-img-container" style="padding: 5px; width: 30%; height: auto;">
    <div class="blur-imgs-wrap">
        <img class="preview" src="data:image/jpeg;base64,/9j/2wBD... ">
        <img class="sharp" onload="onImgLoad(this)" src="http://foo.bar/qux.jpg">
    </div>
</div>