Documentation IndexFetch the complete documentation index at: https://bun.com/docs/llms.txtUse this file to discover all available pages before exploring further.Bun.Image is a chainable image pipeline for decoding, resizing, rotating, and re-encoding JPEG, PNG, WebP, HEIC, and AVIF — built on libjpeg-turbo, spng, libwebp, and SIMD geometry kernels, with zero npm dependencies and no native addon build step. await Bun.file("photo.jpg").image().resize(400, 400, { fit: "inside" }).webp({ quality: 80 }).write("thumb.webp"); The API is shaped after Sharp: construct from an input, chain transforms, pick an output format, then await a terminal method. Nothing runs until the terminal is awaited, and the work executes off the JavaScript thread. Input The constructor accepts a path, bytes, or a Blob — including Bun.file() and Bun.s3(). Blob#image() is shorthand for new Bun.Image(blob): new Bun.Image("./photo.jpg"); // file path new Bun.Image(buffer); // Buffer / ArrayBuffer / TypedArray new Bun.Image(Bun.file("photo.jpg")); // BunFile (read lazily, off-thread) Bun.file("photo.jpg").image(); // same as above Bun.s3("bucket/photo.jpg").image(); // S3File The format is sniffed from the bytes — extensions and Content-Type are ignored. Path strings are filesystem paths. Don’t pass user-controlled strings directly to the constructor — that’s an arbitrary-file-read primitive. Read untrusted input into a Buffer (e.g. via fetch/Bun.file with your own validation) and pass the bytes. When passing a TypedArray/ArrayBuffer, don’t mutate it while a terminal is pending — decode runs off-thread and borrows the bytes. SharedArrayBuffer and resizable buffers are refused; use buf.slice() to pass a fixed view. A second options argument guards against decompression bombs and controls EXIF handling: new Bun.Image(input, { // Reject if width*height > this. Checked after reading the header, // before allocating the pixel buffer. Default matches Sharp (~268 MP). maxPixels: 4096 * 4096, // Apply JPEG ...
First seen: 2026-05-23 23:45
Last seen: 2026-05-24 00:46