返回资讯中心
外部精选
软件工程
#开发者实时流

JPEG XL with WebGPU makes smaller files than libjxl in 150 KB JavaScript

JPEG XL encoder in JavaScript. Smaller files than libjxl at the same quality, a quality search that runs on WebGPU,

Hacker News 最新jackskip222026/10/25 · 19 天前6 分钟阅读

以下正文同步自 Hacker News 最新,版权归原站所有,已转换为易读排版。

JPEG XL encoder in JavaScript. Smaller files than libjxl at the same quality, a quality search that runs on WebGPU, 29 KB gzipped. Runs in browsers, workers, Node and Deno. MIT license, no dependencies.

Method, every score and how to reproduce.

npm install rapier-jxl

Encode pixels to a score

import {encodeToScore} from 'rapier-jxl/score'; const {bytes} = await encodeToScore(rgba, width, height, {target: {ssimulacra2: 80}, gpu: device});

Returns the smallest file that meets the score. gpu is an optional GPUDevice; without it the search runs on the CPU. For a fixed quality, encode(rgba, width, height, {quality: 90}) from rapier-jxl (100 is lossless).

encodeAsync(rgba, width, height, options) writes the same file as encode, on WebGPU when the page has it: a 12 MP phone photo in about 2.1 s instead of 6.7 s (24 phone photos, median, NVIDIA T4).

Copy node_modules/rapier-jxl/dist/rapier-still-worker.js beside your page (rapier-worker.js adds animation), then:

import {toJXL} from 'rapier-jxl/image'; const jxl = await toJXL(file, {worker: './rapier-still-worker.js'}); // an image/jxl Blob

For one offline HTML file, embed the worker as text (example).

Build / import Gzip bytes Capabilities

Still worker · rapier-jxl/rapier/still-worker 149,572 Core + effort 1–9, optional WASM, Photo, JPEG transcoding and parallel lossless groups. No animation.

Complete worker · rapier-jxl/rapier/worker 214,332 Everything in the still worker, plus animation and the other format writers.

Complete module · rapier-jxl/rapier/min 214,402 The complete system with an encoder factory and worker installer.

Image · rapier-jxl/image/min 1,184 One call from a page: a file, bitmap, image data or canvas in, an image/jxl Blob out, through either worker.

Core · rapier-jxl/min 28,920 Lossless or lossy typed RGBA, native precision, HDR and exact alpha.

Effort · rapier-jxl/effort/min 78,503 Core with lossless compression search, efforts 1–9.

WASM · rapier-jxl/wasm/min 88,190 Effort with inlined WASM and JavaScript fallback.

Photo · rapier-jxl/photo/min 60,943 Lossy photographs from RGBA pixels.

JPEG · rapier-jxl/jpeg/min 32,866 Existing JPEGs, preserving admitted coefficients and orientation.

Metadata · rapier-jxl/metadata/min 12,592 Attach, replace or remove caller-supplied Exif/XMP.

Animation · rapier-jxl/animation/min 86,778 Animated JPEG XL from frames: only changed rectangles stored, exact timing, lossless or lossy.

Sizes are standalone files gzipped at level 9. Entry points and embedding.

API · Comparisons · Agent reference · Agent skills · Browser example

正文由 探How 从来源站点 RSS 同步,内容未经改写;遇到排版缺失或需要图片、视频时请以原文为准。

打开原文
去社区讨论 →