web-images
TypeScript icon, indicating that this package has built-in type declarations

0.0.21 • Public • Published

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

[‡]: See benchmarks here

Package Sidebar

Install

npm i web-images

Weekly Downloads

0

Version

0.0.21

License

MIT

Unpacked Size

7.68 MB

Total Files

14

Last publish

Collaborators

  • colbyn