import { useState, useRef } from 'react'; import { Upload, Download, Image as ImageIcon, AlertCircle } from 'lucide-react'; export default function App() { const [selectedImage, setSelectedImage] = useState(null); const [croppedImages, setCroppedImages] = useState([]); const canvasRef = useRef(null); const fileInputRef = useRef(null); const handleImageUpload = (e) => { const file = e.target.files[0]; if (file) { const reader = new FileReader(); reader.onload = (e) => { const img = new Image(); img.onload = () => { const canvas = document.createElement('canvas'); const ctx = canvas.getContext('2d'); canvas.width = 531; canvas.height = 413; const scale = Math.max(canvas.width / img.width, canvas.height / img.height); const x = (canvas.width - img.width * scale) / 2; const y = (canvas.height - img.height * scale) / 2; ctx.fillStyle = 'white'; ctx.fillRect(0, 0, canvas.width, canvas.height); ctx.drawImage(img, x, y, img.width * scale, img.height * scale); setSelectedImage(canvas.toDataURL()); generateA4Layout(canvas.toDataURL()); }; img.src = e.target.result; }; reader.readAsDataURL(file); } }; const generateA4Layout = (croppedImage) => { const canvas = canvasRef.current; const ctx = canvas.getContext('2d'); canvas.width = 2480; canvas.height = 3508; ctx.fillStyle = 'white'; ctx.fillRect(0, 0, canvas.width, canvas.height); const img = new Image(); img.onload = () => { const positions = [ { x: 474, y: 413 }, { x: 1475, y: 413 }, { x: 474, y: 1476 }, { x: 1475, y: 1476 }, { x: 974, y: 2539 }, ]; positions.forEach(pos => { ctx.drawImage(img, pos.x, pos.y, img.width, img.height); }); }; img.src = croppedImage; }; const downloadA4 = () => { const canvas = canvasRef.current; const link = document.createElement('a'); link.download = 'photo-arrangement.png'; link.href = canvas.toDataURL(); link.click(); }; return (
{/* Header */}

Photo ID Arranger

Create professional passport-style photo arrangements. Upload your photo and get a perfectly formatted A4 layout.

{/* Left Column - Controls */}
fileInputRef.current.click()}>
Drop your photo here
or click to browse
Your photo will be automatically cropped to 45x35mm format and arranged 5 times on an A4 page for optimal printing.
{selectedImage && ( )}
{/* Right Column - Preview */}
{selectedImage ? ( <>

Single Photo Preview (45x35mm)

Cropped preview

A4 Layout Preview

) : (

Upload a photo to see the preview

)}
); }