-
-
Notifications
You must be signed in to change notification settings - Fork 302
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement libheif v1.19.3 instead of heic2any to prevent browser cras…
…hes with some iOS 18 heic image files
- Loading branch information
1 parent
00d2757
commit fb6fe7a
Showing
9 changed files
with
110 additions
and
31 deletions.
There are no files selected for viewing
This file contains 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
function HeifConvert(libheif) { | ||
this.libheif = libheif; | ||
this.decoder = new libheif.HeifDecoder(); | ||
} | ||
|
||
|
||
HeifConvert.prototype.convert = async function (buffer) { | ||
const decodeResult = this.decoder.decode(buffer); | ||
const image = decodeResult[0]; | ||
|
||
let w = image.get_width(); | ||
let h = image.get_height(); | ||
const canvas = document.createElement("canvas"); | ||
canvas.width = w; | ||
canvas.height = h; | ||
|
||
const ctx = canvas.getContext("2d"); | ||
const imageData = ctx.createImageData(w, h); | ||
|
||
await copyData(imageData, image); | ||
|
||
ctx.putImageData(imageData, 0, 0); | ||
image.free(); | ||
return canvas; | ||
}; | ||
|
||
function copyData(dataContainer, image) { | ||
return new Promise((resolve, reject) => { | ||
image.display( | ||
dataContainer, | ||
function () { | ||
resolve() | ||
} | ||
); | ||
}) | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
This file contains 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
This file contains 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
This file contains 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