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

thumbo

v1.0.8

Published

Dead fast thumbnail library for browser and NodeJs

Downloads

356

Readme

A high-performant thumbnail creation library

Build & Test

Built with Rust 🦀 & WebAssembly 🕸

✅ Features

  • High-performance
  • Web worker pool
  • Built with Rust & Web Assembly
  • Uses transferable objects
  • Easy to use APIs
  • Supports Png, Jpeg, Gif, Ico and Svg

🚴 Usage

Install the package from npm:

yarn add thumbo
import Thumbo, { Transfer } from "thumbo";

Thumbo.init().then(async () => {
  Thumbo.thumbnail(
    Transfer(await (await fetch("/path/to/img.png")).arrayBuffer()),
    Thumbo.ImageFormat.Png,
    20,
    20
  ).then((thumbnailBuffer) => {
    document.getElementById("img1").src = URL.createObjectURL(
      new Blob([thumbnailBuffer])
    );
  });

  Thumbo.thumbnailFromUrl(
    "https://example.com/image.png",
    Thumbo.ImageFormat.Png,
    20,
    20
  ).then((thumbnailBuffer) => {
    document.getElementById("img2").src = URL.createObjectURL(
      new Blob([thumbnailBuffer])
    );
  });
});

⚙️ API Reference

Thumbo.init(config: InitOptions): Promise<void>

Initiates thumbo. The initiation proccess includes:

  • Downloads the thumbo-core WebAssembly bundle from unpkg.com
  • Complies the WASM binary
  • Starts a pool of web workers(8 workers are pooled by default, however, you can control the number of wokers to be spawned) to take thumbnail creation tasks
  • After the afore mentioned steps are completed, isInitialized field is set true.

InitOptions

InitOptions interface provides the configuration for the init method.

interface InitOptions {
  /** Url to fetch the thumbo-core WASM bundle. Defaults to the bundle hosted on unpkg. */
  wasmUrl?: string;
  /** Maximum no. of tasks to run on one worker thread at a time. Defaults to one. */
  concurrency?: number;
  /** Maximum no. of jobs to be queued for execution before throwing an error. */
  maxQueuedJobs?: number;
  /** Gives that pool a name to be used for debug logging, letting you distinguish between log output of different pools. */
  name?: string;
  /** No. of worker threads to spawn and to be managed by the pool. */
  size?: number;
}

Transfer(transferable: Transferable): TransferDescriptor

Mark transferable objects within an arbitrary object or array as being a transferable object. They will then not be serialized and deserialized on messaging with the main thread, but ownership of them will be tranferred to the receiving thread.

Only array buffers, message ports and few more special types of objects can be transferred, but it's much faster than serializing and deserializing them.

Returns a TransferDescriptor, a container that holds the arraybuffer to be transferred.

Note: The transferable object cannot be accessed by this thread again unless the receiving thread transfers it back again!

Transferable: transferable Array buffer, message port or similar.

See https://developers.google.com/web/updates/2011/12/Transferable-Objects-Lightning-Fast

Thumbo.ImageFormat

Enums of supported image formats. Thumbo supports thumbnail creation for the following formats:

  • Png
  • Jpeg
  • Gif
  • Ico
  • Svg

Thumbo.thumbnail(bufferDescriptor: TransferDescriptor, format: ImageFormat, width: number, height: number): Promise<ArrayBuffer>

Creates a thumbnail from the provided arraybuffer transfer descriptor. The provided arraybuffer is transferred to the worker for processing, once the task is completed, the newly created thumbnail arraybuffer is transferred back to the main thread.

Thumbo.thumbnailFromUrl(url: string, format: ImageFormat, width: number, height: number): Promise<ArrayBuffer>

Creates a thumbnail from the provided Url. Once the task is completed, the created thumbnail arraybuffer is transferred to the main thread.

Thumbo.workers

Returns the workers in the pool

Note: Accessing this property before thumbo is initialized will throw an error.

Thumbo.completed(allowResolvingImmediately: boolean)

Returns a promise that resolves once the task queue is emptied. Promise will be rejected if any task fails.

allowResolvingImmediately Set to true to resolve immediately if task queue is currently empty.

Thumbo.settled(allowResolvingImmediately: boolean)

Returns a promise that resolves once the task queue is emptied. Failing tasks will not cause the promise to be rejected.

allowResolvingImmediately Set to true to resolve immediately if task queue is currently empty.

Note: Calling this function before thumbo is initialized will throw an error.

Thumbo.uninit(force: boolean)

Returns a promise that resolves once the task queue is emptied. Failing tasks will not cause the promise to be rejected.

force Set to true to kill the thread even if it cannot be stopped gracefully.

Note: Calling this function before thumbo is initialized will throw an error.