Use Cases
Browser Uploader Flow
Generate placeholders in the browser when users upload images in client UI.
When this pattern fits
Use this pattern when images are selected by users and should not be uploaded just to generate a placeholder.
Client-side encode
import { encode } from 'blurkit/browser'
async function handleFile(file: File) { const result = await encode(file, { algorithm: 'thumbhash', size: 32, })
return { blurDataURL: result.dataURL, blurHash: result.hash, width: result.meta.originalWidth, height: result.meta.originalHeight, }}What to store
- Use
FileorBlobinput for local user images. metafields can be stored with upload payloads.thumbhashproduces a shorter hash string thanblurhash. That does not automatically shrinkdataURL: the rendered bytes depend on the image dimensions andoutputFormat, so compare the storeddataURLsize if payload budget is the concern.
Caveats
- Remote URL input requires CORS.
- Browser runtime cannot read local path strings.