Function: rawImageToEncodedBytes()
ts
function rawImageToEncodedBytes(
image: RawImageLike,
encodeImage?: (image: RawImageLike) => Promise<Uint8Array<ArrayBufferLike>>,
): Promise<Uint8Array<ArrayBufferLike>>;Defined in: src/batteries/generation/transformers_js/helpers.ts:57
Encodes a resolved RawImage-like value to PNG bytes.
Parameters
| Parameter | Type | Description |
|---|---|---|
image | RawImageLike | The RawImage-like value to encode (one element of generate_images()'s result). |
encodeImage? | (image: RawImageLike) => Promise<Uint8Array<ArrayBufferLike>> | Optional override that fully replaces the env-branch. |
Returns
Promise<Uint8Array<ArrayBufferLike>>
The encoded PNG bytes.
Remarks
When encodeImage is supplied it takes over entirely — the primary hermetic-test seam, since a fake RawImage double need not implement toBlob/toSharp at all. Otherwise this picks the browser (toBlob) or Node (toSharp) path by a local environment probe, falling back to whichever method is actually present on image if the probe disagrees with reality (e.g. a web worker with neither window nor document, but a toBlob-only RawImage).