mirror of
https://github.com/schlagmichdoch/PairDrop.git
synced 2025-04-21 15:26:17 -04:00
Implement libheif v1.19.3 instead of heic2any to prevent browser crashes with some iOS 18 heic image files
This commit is contained in:
parent
00d2757fdc
commit
fb6fe7ae61
9 changed files with 110 additions and 31 deletions
36
public/scripts/heif-convert.js
Normal file
36
public/scripts/heif-convert.js
Normal file
|
@ -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()
|
||||
}
|
||||
);
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue