Repository navigation
Cookbook
Dus Mamud edited this page Nov 9, 2026
·
1 revision
Twelve recipes for the jobs people actually do. Every pattern here runs in the playground or the consumer test — the docs site cookbook carries the extended versions.
import { processImage } from '@dusrel/image';
const result = await processImage(file, {
format: 'image/webp',
maxSizeBytes: 200_000,
});
console.log(result.targetSizeMet); // honest answer, either wayimport { processImage } from '@dusrel/image';
import { encode } from '@dusrel/image-avif';
await processImage(file, {
format: 'image/avif',
codecs: [{ mimeType: 'image/avif', encode: (d) => encode(d, { quality: 50, speed: 9 }) }],
});import { decodeHeic } from '@dusrel/image-heic';
import { encode } from '@dusrel/image-jpeg';
const pixels = await decodeHeic(heicBytes); // native on Safari 17+, WASM elsewhere
const jpegBlob = await encode(pixels, { quality: 82 });import { stripMetadata } from '@dusrel/image-metadata';
const noGps = await stripMetadata(bytes, { mode: 'gps-only' });
const clean = await stripMetadata(bytes, { mode: 'all' });import { readMetadata } from '@dusrel/image-metadata';
const info = await readMetadata(bytes);
console.log(info.format, info.exif?.make, info.exif?.gps); // { latitude, longitude }import { pipeline, imageDataPlugin } from '@dusrel/image';
import { drawTextWatermark } from '@dusrel/image-watermark';
await pipeline(file)
.use(imageDataPlugin({
name: 'watermark',
transform: (d) => drawTextWatermark(d, '© Dusrel', { position: 'bottom-right' }),
}))
.run();import { blobToImageData } from '@dusrel/image';
import { encodeThumbHash, thumbHashToBase64, encodeBlurHash } from '@dusrel/image-placeholder';
const data = await blobToImageData(file);
const thumb = thumbHashToBase64(encodeThumbHash(data));
const blur = encodeBlurHash(data);import { encode } from '@dusrel/image-gif';
const gif = await encode([{ data: frame1 }, { data: frame2, delay: 120 }], { repeat: 0 });import { blobToImageData } from '@dusrel/image';
import { resize } from '@dusrel/image-resize';
const data = await blobToImageData(file);
const small = resize(data, { width: 800, height: 600, filter: 'lanczos3' });import { optimize } from '@dusrel/image-oxipng';
const smaller = await optimize(pngBytes, { level: 3 }); // → ArrayBufferimport { processBatch } from '@dusrel/image';
const results = await processBatch(files, { format: 'image/webp', quality: 0.8 });For worker pools, retries and memory caps, see @dusrel/image-batch
(runBatch, createWorkerPool) in the Package Guide.
import { optimizeSvg } from '@dusrel/image-svg';
const optimized = await optimizeSvg(svgText); // SVGO, multipass by defaultNext: Package Guide · Codec Guide
Released under the MIT License · © 2026 Dus Mamud · A Dusrel project · The HEIC engine (libheif/libde265) is LGPL-3.0, fenced to @dusrel/image-heic · Docs · Playground
Start here
Reference
Project
Elsewhere