@cfbl/image-sdk
v0.1.0
Published
Fast, privacy-first client-side image optimization SDK
Maintainers
Readme
🌌 Hikaru Image SDK
Fast, privacy-first client-side image optimization for modern web apps.
Compress images before they leave the user's device. Save server bandwidth, cut storage costs, and protect user privacy instantly.
✨ The Magic Inside
- 🔒 100% Client-Side: Processing happens entirely in the browser. No servers required.
- 🧹 Auto EXIF Stripping: Automatically removes GPS coords, device models, and camera data.
- ⚡ Hardware Accelerated: Uses
OffscreenCanvas&createImageBitmapoff the main UI thread. - 📦 Tiny Footprint: Zero dependencies. Extremely lightweight.
🚀 Installation
npm install @hikarulabs/image-sdk
💻 Developer Playground
We designed the API to be as simple or as powerful as you need it to be.
1. The "Zero Config" One-Liner
Automatically scales down massive phone photos to a web-safe size (max 1920px) at 80% quality.
TypeScript
import { compress } from "@hikarulabs/image-sdk";
const optimized = await compress(file);
2. The "Preset" Shorthand
Standardizing user uploads? Just pass a preset string. Available presets: 'avatar', 'thumbnail', 'feed', 'hero'.
TypeScript
const avatar = await compress(file, "avatar");
3. The "Batch" Uploader
Pass an array of files, and we'll process them sequentially to prevent browser memory crashes, complete with a progress hook.
TypeScript
const results = await compress(
[file1, file2, file3],
"feed",
(completed, total, currentFile) => {
console.log(`✅ Processed ${completed}/${total}: ${currentFile.name}`);
}
);
4. The "Exact Control" Object
Need exact pixel dimensions or to force a modern format like WebP?
TypeScript
const custom = await compress(file, {
width: 800, // Auto-calculates proportional height
quality: 0.75, // 75% quality
format: "webp", // Convert to WebP
keepOriginalIfSmaller: true // Safety guard!
});
🛠 Advanced API Reference
TypeScript
interface CompressOptions {
preset?: "auto" | "avatar" | "thumbnail" | "feed" | "hero";
quality?: number; // 0.1 to 1.0
width?: number; // Exact width in px
height?: number; // Exact height in px
maxWidth?: number; // Scale down if width exceeds this
maxHeight?: number; // Scale down if height exceeds this
format?: "jpeg" | "jpg" | "webp" | "png";
keepOriginalIfSmaller?: boolean; // Default: true
}