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-resize-wasm

v1.2.0

Published

WASM package to resize images by height, width, or both.

Downloads

18

Readme

image-resize-wasm

a full resolution image on the left with cropped and resized versions overlaid on top each other to the right.

Resize images by width, height, or both using the Rust Image crate and WASM.

This package uses wasm-pack as a build tool. The origin of this project was to use an Edge Function to resize images on the fly.

Usage

Vercel Edge Function

https://vercel.com/docs/functions/edge-functions/wasm

Warning This example is currently nonfunctional!

The following example works with vercel dev, but failes to deploy with the following error:

Error: The Edge Function "api/[resize]" is referencing unsupported modules:
        - image-resize-wasm: vc-blob-asset:image_resize_wasm_bg.wasm

I was eventually able to "fix" the build by manually changing the build outputs, however I couldn't get the example working.

RuntimeError: unreachable
    at (wasm://wasm/001256da:1:169628)
    at (wasm://wasm/001256da:1:209588)
    at (wasm://wasm/001256da:1:186105)
    at (wasm://wasm/001256da:1:193864)
    at (node_modules/.pnpm/[email protected]/node_modules/image-resize-wasm/image_resize_wasm_bg.js:48:0)
    at (api/[resize].js:44:62)
// api/index.ts
// http://localhost:3000/api?url=https://example.com/example.png&w=1024

// @ts-ignore
import wasm from "image-resize-wasm/image_resize_wasm_bg.wasm?module";
import init, {
  scale_by_width,
  scale_by_height,
  resize,
} from "image-resize-wasm";

export const config = {
  runtime: "edge",
};

export default async function handler(request: Request) {
  await init(wasm);
  const { searchParams } = new URL(request.url);
  const url = searchParams.get("url"),
    wString = searchParams.get("w"),
    hString = searchParams.get("h");

  if (!url || (!wString && !hString)) throw new Error();
  const w = Number(wString),
    h = Number(hString);

  const response = await fetch(url);
  const imageUint8Array = new Uint8Array(await response.arrayBuffer());

  let scaledImage;
  if (w && h) {
    scaledImage = resize(imageUint8Array, w, h);
  } else if (w) {
    scaledImage = scale_by_width(imageUint8Array, w);
  } else if (h) {
    scaledImage = scale_by_height(imageUint8Array, h);
  }

  return new Response(scaledImage, {
    status: 200,
    headers: {
      "Content-Type": "image/jpeg",
    },
  });
}

Contributing

Build

wasm-pack build --target web

Publish

cd pkg
pnpm publish

License

Copyright © 2023 Alexander Liu

MIT License