[feat] added inlay emotion/imggen & rework imggen

This commit is contained in:
kwaroran
2023-11-27 21:50:43 +09:00
parent d71ef1b8a2
commit 1d15eacd72
12 changed files with 428 additions and 340 deletions

View File

@@ -24,12 +24,21 @@ export async function postInlayImage(){
const extention = img.name.split('.').at(-1)
//darw in canvas to convert to png
const imgObj = new Image()
imgObj.src = URL.createObjectURL(new Blob([img.data], {type: `image/${extention}`}))
return await writeInlayImage(imgObj, {
name: img.name,
ext: extention
})
}
export async function writeInlayImage(imgObj:HTMLImageElement, arg:{name?:string, ext?:string} = {}) {
let drawHeight = 0
let drawWidth = 0
const canvas = document.createElement('canvas')
const ctx = canvas.getContext('2d')
const imgObj = new Image()
let drawHeight, drawWidth = 0
imgObj.src = URL.createObjectURL(new Blob([img.data], {type: `image/${extention}`}))
await new Promise((resolve) => {
imgObj.onload = () => {
drawHeight = imgObj.height
@@ -59,9 +68,9 @@ export async function postInlayImage(){
const imgid = v4()
await inlayStorage.setItem(imgid, {
name: img.name,
name: arg.name ?? imgid,
data: dataURI,
ext: extention,
ext: arg.ext ?? 'png',
height: drawHeight,
width: drawWidth
})