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

image_2_html

v0.0.9

Published

A library to convert an image buffer into html, with a blurred represenatation of the image to be used as a background or placeholder.

Downloads

36

Readme

Image_2_HTML

This small tool was inspired by Unsplash's lazy loading process. It converts an image file stream into a set of divs that appear as a blurred version of the image. Using divs instead of an image thumbnail as a placeholder creates a very quick page load time. The html output for an image is only around 1.5kb. The idea is, when you upload an image to your site's api, you use this library to generate an html string, which you can then store in your database. Then, when server side rendering a page, instead of inserting an image tag, you insert the generated html, then later lazyload the final image.

This library only works with server-side node. The underlying library (sharp) will not work in browser based apps.

Usage is very straightforward:

image2html(width, height, blurAmount, imageBuffer)

const image2html = require('image_2_html');
image2html("500px", "350px", 50, imageBuffer).then((html) => doSomethingWithHTML()));

The output will appear in the following format:


    <div style="height: 350px; width: 500px; overflow: hidden;">
      <div style="background: rgb(234,166,82); width: 100%; height: 100%;">
        <div style="display: flex; width: 100%; height: 100%; flex-wrap: wrap; filter: blur(50px);">
          <div style="background: rgb(66,135,117); width: 25%; height: 25%"></div>
          <div style="background: rgb(116,177,162); width: 25%; height: 25%"></div>
          <div style="background: rgb(227,219,212); width: 25%; height: 25%"></div>
          <div style="background: rgb(87,156,139); width: 25%; height: 25%"></div>
          <div style="background: rgb(143,37,23); width: 25%; height: 25%"></div>
          <div style="background: rgb(94,111,54); width: 25%; height: 25%"></div>
          <div style="background: rgb(239,226,219); width: 25%; height: 25%"></div>
          <div style="background: rgb(234,166,82); width: 25%; height: 25%"></div>
          <div style="background: rgb(233,220,213); width: 25%; height: 25%"></div>
          <div style="background: rgb(105,157,140); width: 25%; height: 25%"></div>
          <div style="background: rgb(229,187,146); width: 25%; height: 25%"></div>
          <div style="background: rgb(138,159,135); width: 25%; height: 25%"></div>
          <div style="background: rgb(238,226,220); width: 25%; height: 25%"></div>
          <div style="background: rgb(107,165,150); width: 25%; height: 25%"></div>
          <div style="background: rgb(245,185,87); width: 25%; height: 25%"></div>
          <div style="background: rgb(234,199,153); width: 25%; height: 25%"></div>
        </div>
      </div>
    </div>

So this image

alt text

Generates this set of styled divs

alt text

A couple examples of retreiving an image buffer:

Using fs:

const imageBuffer = fs.readFileSync('somefile.jpg')

Using node-fetch on an image url:

const imageBuffer = await fetch(url)
    .then((res) => res.arrayBuffer())
    .then((resA) => {
      return Buffer.from(resA);
    });
image2html("50%", "35%", 50, image).then((html) => console.log(html));