Bun.Image
3 hours ago
- #image processing
- #web development
- #Bun.js
- Bun.Image is a chainable image processing pipeline for JPEG, PNG, WebP, HEIC, and AVIF formats, built on fast libraries like libjpeg-turbo and libwebp with no npm dependencies.
- Images can be created from file paths, buffers, or Blobs. It's important to avoid passing user-controlled strings directly due to security risks; use validated bytes.
- Resize operations support different fit modes and filters, with Lanczos3 as the default for sharp photos. Decoding can skip unnecessary steps for large JPEGs.
- Rotation, flipping, and modulation (brightness, saturation) are available transformations.
- Output formats include JPEG, PNG, WebP, HEIC, and AVIF with configurable quality, compression, and palette settings.
- Terminal methods like .bytes(), .blob(), and .write() trigger processing and return results. Placeholders and progressive JPEGs can improve web performance.
- Bun.Image integrates with Bun.serve for server-side image handling and supports clipboard operations on macOS and Windows.
- Formats and performance vary by backend: system backend uses OS libraries on macOS/Windows, while bun backend ensures consistent output across platforms.