-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
30 lines (26 loc) · 935 Bytes
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const heicConvert = import('heic-convert/browser.js');
import { fileInputSource, getFileList, getControls } from './common.js';
const fileList = getFileList('fileList');
const controls = getControls('controls');
function convertHEIC(arrayBuffer, format) {
const inputBuffer = new Uint8Array(arrayBuffer);
return heicConvert.then((conv) =>
conv.default({
buffer: inputBuffer,
format: format.toUpperCase(),
quality: controls.quality,
})
);
}
function handleFile(file) {
const fileEntry = fileList.add(file);
const reader = new FileReader();
reader.onload = async () => {
const format = controls.format;
const outputBuffer = await convertHEIC(reader.result, format);
const blob = new Blob([outputBuffer], { type: `image/${format}` });
fileEntry.downloadReady(blob, format, controls.autoDownload);
};
reader.readAsArrayBuffer(file);
}
fileInputSource('fileInput', handleFile);