Transforms an image in one call.
The entry point to reach for. It builds a plan from the options, lets the planner pull only the source it needs, and hands back the encoded result:
import wasm from '@gmitch215/tinyimg/tinyimg.wasm';import { TinyImgModule, transform } from '@gmitch215/tinyimg';const tinyimg = TinyImgModule.load(wasm);export default { async fetch(request: Request): Promise<Response> { const source = await fetch('https://example.com/photo.jpg'); const result = await transform(tinyimg, source, { width: 800, height: 600, fit: 'cover', format: 'webp', quality: 80 }); return result.response({ 'cache-control': 'public, max-age=86400' }); }}; Copy
import wasm from '@gmitch215/tinyimg/tinyimg.wasm';import { TinyImgModule, transform } from '@gmitch215/tinyimg';const tinyimg = TinyImgModule.load(wasm);export default { async fetch(request: Request): Promise<Response> { const source = await fetch('https://example.com/photo.jpg'); const result = await transform(tinyimg, source, { width: 800, height: 600, fit: 'cover', format: 'webp', quality: 80 }); return result.response({ 'cache-control': 'public, max-age=86400' }); }};
The handle is released before this returns, so there is nothing to dispose. Use Image directly when you want two encodings of one transformation, or an operation this option object does not cover.
The loaded module.
The encoded image, in any shape Source accepts.
What to do to it. An empty object decodes and re-encodes.
The encoded result and its conveniences.
Transforms an image in one call.
The entry point to reach for. It builds a plan from the options, lets the planner pull only the source it needs, and hands back the encoded result:
The handle is released before this returns, so there is nothing to dispose. Use Image directly when you want two encodings of one transformation, or an operation this option object does not cover.