Add multiple option to convert every image in a HEIC file - #32
Open
svd-sea wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.heicTonow acceptsmultiple: trueand 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.tsfiles gain two overloads for that, andsrc/iife.jsneeds no change at allbecause 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 thedist/diff in this pull request is only this change.