diff --git a/src/components/images/ImageCard.tsx b/src/components/images/ImageCard.tsx index 597ec9c..1899fa3 100644 --- a/src/components/images/ImageCard.tsx +++ b/src/components/images/ImageCard.tsx @@ -114,7 +114,7 @@ export function ImageCard({ {item.processedBlob && ( -
+
)} diff --git a/src/lib/client/bgRemover.ts b/src/lib/client/bgRemover.ts index aee2427..963f0ab 100644 --- a/src/lib/client/bgRemover.ts +++ b/src/lib/client/bgRemover.ts @@ -63,13 +63,23 @@ export function compositeOnWhite(pngBlob: Blob, feather: number): Promise fgCtx.globalCompositeOperation = 'source-over' } + // Canvas de sortie 1000×1000 blanc, sujet centré avec padding de 5% + const SIZE = 1000 + const PADDING = 0.05 + const available = Math.round(SIZE * (1 - PADDING * 2)) + const scale = Math.min(available / width, available / height) + const dw = Math.round(width * scale) + const dh = Math.round(height * scale) + const dx = Math.round((SIZE - dw) / 2) + const dy = Math.round((SIZE - dh) / 2) + const out = document.createElement('canvas') - out.width = width - out.height = height + out.width = SIZE + out.height = SIZE const ctx = out.getContext('2d')! ctx.fillStyle = '#ffffff' - ctx.fillRect(0, 0, width, height) - ctx.drawImage(fgCanvas, 0, 0) + ctx.fillRect(0, 0, SIZE, SIZE) + ctx.drawImage(fgCanvas, dx, dy, dw, dh) URL.revokeObjectURL(objectUrl) out.toBlob(