lit 2.5.0, and cap image max dimentions.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4074 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2022-12-10 00:35:53 +00:00
parent 4080266fa3
commit 82f9859c57
4 changed files with 33 additions and 31 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -66,10 +66,13 @@ class TfComposeElement extends LitElement {
let img = new Image();
img.onload = function() {
let canvas = document.createElement('canvas');
canvas.width = img.width;
canvas.height = img.height;
let width_scale = Math.min(img.width, 1024) / img.width;
let height_scale = Math.min(img.height, 1024) / img.height;
let scale = Math.min(width_scale, height_scale);
canvas.width = img.width * scale;
canvas.height = img.height * scale;
let context = canvas.getContext('2d');
context.drawImage(img, 0, 0);
context.drawImage(img, 0, 0, canvas.width, canvas.height);
let data_url = canvas.toDataURL('image/webp');
let result = atob(data_url.split(',')[1]).split('').map(x => x.charCodeAt(0));
resolve(result);