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

web-images

v0.0.21

Published

Safe - Fast (and Non Blocking) - Dependency free - MIT License (with no GPL extras) - Image Loading, Resizing, Conversion and Processing

Downloads

44

Readme

Documentation

GitRepo

Example

import {Image} from "web-images";
import {basename} from "path";
import * as fs from "fs";

async function load_and_save_fast(path: string): Promise<null> {
    // Assume `path` has a file extension set to “jpeg”.
    const output_path = `./output/${basename(path, "jpeg")}.png`;
    return Image
        .open(path)
        .then((x: Image) => x.thumbnail({
            width: 500,
            height: 500
        }))
        .then((x: Image) => x.save(output_path))
        .then((_) => {
            console.log("done");
            return null;
        });
}

async function load_and_save_quality(path: string): Promise<null> {
    // Assume `path` has a file extension set to “jpeg”.
    const output_path = `./output/${basename(path, "jpeg")}.png`;
    return Image
        .open(path)
        .then((x: Image) => x.resize({
            width: 500,
            height: 500
        }))
        .then((x: Image) => x.save(output_path))
        .then((_) => {
            console.log("done");
            return null;
        });
}

async function load_only(path: string): Promise<Image> {
    return Image
        .open(path)
        .then((x: Image) => x.resize({
            width: 500,
            height: 500,
            resize_exact: false,
            filter_type: "Lanczos3"
        }));
}

Abstract

The bringin of the amazing image crate to the node.js ecosystem.

Rationale

1. License

While e.g. the Sharp library is licensed under the Apache 2.0 License. It’s a wrapper around libvips which is LGPLv3. In contrast, Web Images is self contained and distributable under the MIT license.

Although this may, or may not be significant depending on your specific circumstances.

2. Performance, Safety and ease of Development

Or “why undergo the development of Web Images when libvips is faster”?

First, buy into Rust and it’s advantages over C/C++ implementations. This should filter out all but native JS libraries. Now with regards to Web Images over e.g. Jimp:

Jimp       : ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 80.55 seconds
Web Images : ▇▇ 4.77 seconds

*--------------------------------*
| processing 158 images          |
*--------------------------------*

Miscellaneous

[*]: No annoying system requirements on libvips, ImageMagic and etcetera. There are rust dependencies yet everything is baked into the release binary and requires no further dependencies.

[†]: Bugs are inevitable and furthermore what bridges the JS world with the rust implementation is the low-level NAPI interface. Yet while the picture isn’t perfect, the FFI boundary is rather small in comparison. If you buy into Rust and it’s semantics, this should at the very least be a step in the right direction.

[‡]: See benchmarks here