feat: make AI background removal optional with resize-only upload and batch detour selection
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
export async function resizeToSquare(blob: Blob, size = 1000): Promise<Blob> {
|
||||
const img = await createImageBitmap(blob)
|
||||
const canvas = new OffscreenCanvas(size, size)
|
||||
const ctx = canvas.getContext('2d')!
|
||||
ctx.fillStyle = '#ffffff'
|
||||
ctx.fillRect(0, 0, size, size)
|
||||
const scale = Math.min(size / img.width, size / img.height)
|
||||
const w = img.width * scale
|
||||
const h = img.height * scale
|
||||
const x = (size - w) / 2
|
||||
const y = (size - h) / 2
|
||||
ctx.drawImage(img, x, y, w, h)
|
||||
img.close()
|
||||
return canvas.convertToBlob({ type: 'image/jpeg', quality: 0.92 })
|
||||
}
|
||||
Reference in New Issue
Block a user