change resolution to 1080p and max attempts to 3
This commit is contained in:
parent
cedfa404f2
commit
c90ab9019b
|
@ -424,15 +424,9 @@ class UploadService {
|
||||||
image.setAttribute('src', imageURL);
|
image.setAttribute('src', imageURL);
|
||||||
await new Promise((resolve) => {
|
await new Promise((resolve) => {
|
||||||
image.onload = () => {
|
image.onload = () => {
|
||||||
canvas.width = image.width;
|
canvas.width = 1920;
|
||||||
canvas.height = image.height;
|
canvas.height = 1080;
|
||||||
canvas_CTX.drawImage(
|
canvas_CTX.drawImage(image, 0, 0, 1920, 1080);
|
||||||
image,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
image.width,
|
|
||||||
image.height
|
|
||||||
);
|
|
||||||
image = undefined;
|
image = undefined;
|
||||||
resolve(null);
|
resolve(null);
|
||||||
};
|
};
|
||||||
|
@ -479,10 +473,11 @@ class UploadService {
|
||||||
}
|
}
|
||||||
URL.revokeObjectURL(imageURL);
|
URL.revokeObjectURL(imageURL);
|
||||||
let thumbnailBlob: Blob = file,
|
let thumbnailBlob: Blob = file,
|
||||||
prevSize = file.size;
|
attempts = 0;
|
||||||
let quality = 1;
|
let quality = 1;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
prevSize = thumbnailBlob.size;
|
attempts++;
|
||||||
quality /= 2;
|
quality /= 2;
|
||||||
thumbnailBlob = await new Promise((resolve) => {
|
thumbnailBlob = await new Promise((resolve) => {
|
||||||
canvas.toBlob(
|
canvas.toBlob(
|
||||||
|
@ -493,10 +488,7 @@ class UploadService {
|
||||||
quality
|
quality
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
} while (
|
} while (thumbnailBlob.size > 50000 && attempts < 3);
|
||||||
thumbnailBlob.size > 50000 &&
|
|
||||||
prevSize != thumbnailBlob.size
|
|
||||||
);
|
|
||||||
const thumbnail = this.getUint8ArrayView(thumbnailBlob);
|
const thumbnail = this.getUint8ArrayView(thumbnailBlob);
|
||||||
return thumbnail;
|
return thumbnail;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
Loading…
Reference in a new issue