better downscale

This commit is contained in:
Ondřej Žára 2020-06-23 09:23:14 +02:00
parent 8cdc26ec66
commit 13b3430f51
2 changed files with 12 additions and 4 deletions

View file

@ -802,9 +802,13 @@ async function bytesToImage(bytes) {
}
function resize(image) {
while (Math.min(image.width, image.height) >= 2*artSize) {
let tmp = node("canvas", {width:image.width/2, height:image.height/2});
tmp.getContext("2d").drawImage(image, 0, 0, tmp.width, tmp.height);
image = tmp;
}
const canvas = node("canvas", {width:artSize, height:artSize});
const ctx = canvas.getContext("2d");
ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
canvas.getContext("2d").drawImage(image, 0, 0, canvas.width, canvas.height);
return canvas;
}

View file

@ -23,9 +23,13 @@ async function bytesToImage(bytes) {
}
function resize(image) {
while (Math.min(image.width, image.height) >= 2*conf.artSize) {
let tmp = html.node("canvas", {width:image.width/2, height:image.height/2});
tmp.getContext("2d").drawImage(image, 0, 0, tmp.width, tmp.height);
image = tmp;
}
const canvas = html.node("canvas", {width:conf.artSize, height:conf.artSize});
const ctx = canvas.getContext("2d");
ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
canvas.getContext("2d").drawImage(image, 0, 0, canvas.width, canvas.height);
return canvas;
}