Skip to content

Add multiple option to convert every image in a HEIC file - #32

Open
svd-sea wants to merge 1 commit into
hoppergee:mainfrom
svd-sea:multiple-images
Open

Add multiple option to convert every image in a HEIC file#32
svd-sea wants to merge 1 commit into
hoppergee:mainfrom
svd-sea:multiple-images

Conversation

@svd-sea

@svd-sea svd-sea commented Aug 28, 2026

Copy link
Copy Markdown

A HEIC/HEIF file can contain several images: burst photos, image collections, or the tiles a grid image is composed of. The worker already decodes the whole libheif image list, but only ever uses data[0] and frees the rest unused, so those images are unreachable through the public API.

heicTo now accepts multiple: true and then returns one result per contained image, in file order — Blob[] for a mime type target, ImageBitmap[] for "bitmap". Without the option nothing changes: the worker still resolves the first image only, and every existing call keeps its current return type. The .d.ts files gain two overloads for that, and src/iife.js needs no change at all
because the wrapper passes the argument object straight through.

The images are converted one after another and each canvas is released right after use, so only one canvas is alive at a time (issue #7). In the worker the decodes are sequential as well, so libheif never has more than one decode in flight; the list itself does hold every decoded image until it is posted back, which matches what heic2any did.

Note on scope: this returns the images that are stored in the file as separate images. Frames of an animated HEIF sequence track are not image items and are therefore not included — reaching those would need new JS bindings for libheif's track API, which the bundled wrapper does not expose.

dist/ is rebuilt with esbuild 0.25.12, following this repository's convention of committing the built artifacts. Building the unchanged tree with that version reproduces the committed artifacts byte for byte, so the dist/ diff in this pull request is only this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant