mirror of
https://github.com/schlagmichdoch/PairDrop.git
synced 2025-04-20 07:05:05 -04:00
Implement thumbnail creation for heic images
This commit is contained in:
parent
3238d582cc
commit
86d1aa3560
5 changed files with 88 additions and 19 deletions
|
@ -276,14 +276,28 @@ class PeersUI {
|
|||
files = await mime.addMissingMimeTypesToFiles(files);
|
||||
|
||||
if (files[0].type.split('/')[0] === 'image') {
|
||||
getResizedImageDataUrl(files[0], 80, null, 0.9)
|
||||
.then(dataUrl => {
|
||||
this.$shareModeImageThumb.style.backgroundImage = `url(${dataUrl})`;
|
||||
this.$shareModeImageThumb.removeAttribute('hidden');
|
||||
})
|
||||
.catch(_ => {
|
||||
this.$shareModeFileThumb.removeAttribute('hidden');
|
||||
});
|
||||
try {
|
||||
let image = files[0]
|
||||
|
||||
// Heic files can't be shown by browsers natively --> convert to jpeg
|
||||
if (image.type === "image/heif" || image.type === "image/heic") {
|
||||
let blob = await fileToBlob(image);
|
||||
image = await heic2any({
|
||||
blob,
|
||||
toType: "image/jpeg",
|
||||
quality: 0.9
|
||||
});
|
||||
}
|
||||
|
||||
let imageUrl = URL.createObjectURL(image);
|
||||
this.$shareModeImageThumb.style.backgroundImage = `url(${imageUrl})`;
|
||||
|
||||
await waitUntilImageIsLoaded(imageUrl);
|
||||
this.$shareModeImageThumb.removeAttribute('hidden');
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
this.$shareModeFileThumb.removeAttribute('hidden');
|
||||
}
|
||||
} else {
|
||||
this.$shareModeFileThumb.removeAttribute('hidden');
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue