jSquash

repository·main·Indexed 20 days ago

https://github.com/jamsinclair/jsquash

A collection of WebAssembly-based image codecs for high-performance encoding, decoding, and manipulation in Browsers, Web Workers, and Cloudflare Workers. Includes packages for AVIF (@jsquash/avif), JPEG (@jsquash/jpeg), JPEG XL (@jsquash/jxl), PNG (@jsquash/png), and PNG optimization (@jsquash/oxipng).

Tokens
31K
Snippets
138
Records
151
Agent score
68%

What's inside jSquash

  1. Overview of jSquash packages

    main

    jSquash is a collection of WebAssembly image codecs designed for Browser and Web Worker environments. Unlike Squoosh, these are built for strict environments (like Cloudflare Workers) that do not allow dynamic code execution and do not rely on the TextEncoder/TextDecoder API.

    Available packages include:

    • @jsquash/avif: AVIF encoder/decoder (libavif)
    • @jsquash/jpeg: JPEG encoder/decoder (MozJPEG)
    • @jsquash/jxl: JPEG XL encoder/decoder (libjxl)
    • @jsquash/oxipng: PNG optimizer (Oxipng)
    • @jsquash/png: PNG encoder/decoder (rust PNG crate)
    • @jsquash/qoi: QOI encoder/decoder
    • @jsquash/resize: Image resizer (supports upscaling and downscaling)
    • @jsquash/webp: WebP encoder/decoder (libwebp)
  2. Quickstart: Use jSquash in the Browser via CDN

    main

    The easiest way to use jSquash in a browser environment is by importing modules directly from a CDN like esm.sh. This allows you to decode and encode images without a local build step.

    Note that all jSquash packages are ESM modules. You can target specific versions using the @version syntax in the URL.

    import { decode } from "https://esm.sh/@jsquash/jpeg";
    import { encode } from "https://esm.sh/@jsquash/webp";
    
    const imageResponse = await fetch("https://picsum.photos/200/300.jpg");
    const imageData = await decode(await imageResponse.arrayBuffer());
    const webpImageBuffer = await encode(imageData);
  3. General restrictions and disclaimers for libjpeg-turbo

    main

    When using libjpeg-turbo components, observe these universal restrictions:

    • No Endorsement: You cannot use the name of the IJG, the libjpeg-turbo Project, or its contributors in advertising, publicity, or to endorse/promote products derived from this software without specific prior written permission.
    • No Warranty: The IJG and the libjpeg-turbo Project do not warrant the software to be free of defects and accept no liability for undesirable consequences resulting from its use.
  4. Activate Multithreading for @jsquash/jxl

    main

    By default, encode runs on a single thread. To enable multithreading for faster encoding, follow these steps:

    1. Move your encode calls into a WebWorker.
    2. Configure your web server to send the following security headers (required for SharedArrayBuffer support):
      • Cross-Origin-Opener-Policy: same-origin
      • Cross-Origin-Embedder-Policy: require-corp

    If the browser or device does not support multithreading, the package will automatically fallback to single-threaded mode.

  5. Comply with libjpeg-turbo licenses when distributing binaries or statically linked applications

    main

    If you are distributing only libjpeg-turbo binaries (without source) or an application that statically links with libjpeg-turbo, you must fulfill these documentation requirements:

    1. General Attribution: Your product documentation must include the following message: This software is based in part on the work of the Independent JPEG Group.
    2. TurboJPEG API Attribution: If your binary distribution includes or uses the TurboJPEG API, your product documentation must also include the full text of the Modified (3-clause) BSD License.