[fix] encoding images
This commit is contained in:
@@ -86,4 +86,20 @@ export async function getInlayImage(id: string){
|
||||
export function supportsInlayImage(){
|
||||
const db = get(DataBase)
|
||||
return db.aiModel.startsWith('gptv') || (db.aiModel === 'reverse_proxy' && db.proxyRequestModel?.startsWith('gptv'))
|
||||
}
|
||||
|
||||
export async function reencodeImage(img:Uint8Array){
|
||||
const canvas = document.createElement('canvas')
|
||||
const imgObj = new Image()
|
||||
imgObj.src = URL.createObjectURL(new Blob([img], {type: `image/png`}))
|
||||
await imgObj.decode()
|
||||
let drawHeight = imgObj.height
|
||||
let drawWidth = imgObj.width
|
||||
canvas.width = drawWidth
|
||||
canvas.height = drawHeight
|
||||
const ctx = canvas.getContext('2d')
|
||||
ctx.drawImage(imgObj, 0, 0, drawWidth, drawHeight)
|
||||
const b64 = canvas.toDataURL('image/png').split(',')[1]
|
||||
const b = Buffer.from(b64, 'base64')
|
||||
return b
|
||||
}
|
||||
Reference in New Issue
Block a user