This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2025-04-02 13:29:28 +07:00
parent 6f07e15a78
commit aed5362e86

View file

@ -261,48 +261,14 @@ async function capturePhoto() {
0.5
)
if (!imageBlob) return
const fileName = 'photo.png'
// Canvas
const imgElement = new Image()
imgElement.src = URL.createObjectURL(imageBlob)
await imgElement.decode()
// 1024px
const maxSize = 1024
let { width, height } = imgElement
if (width > maxSize || height > maxSize) {
if (width > height) {
height *= maxSize / width
width = maxSize
} else {
width *= maxSize / height
height = maxSize
}
}
// Canvas
const canvas = document.createElement('canvas')
canvas.width = width
canvas.height = height
const ctx = canvas.getContext('2d')
if (ctx) {
ctx.drawImage(imgElement, 0, 0, width, height)
}
// Canvas Blob
const resizedBlob: Blob = await new Promise((resolve) =>
canvas.toBlob((blob) => resolve(blob!), 'image/png', 0.8)
)
const fileName = 'photo.jpg'
//
const file = new File([resizedBlob], fileName, { type: 'image/png' })
const file = new File([imageBlob], fileName, { type: 'image/png' })
fileImg.value = file
//
await camera.value?.stop()
const url = URL.createObjectURL(resizedBlob)
const url = URL.createObjectURL(imageBlob)
img.value = url
console.log(file)
}
/** function เปลี่ยนรูปภาพ*/