Please bookmark this page to avoid losing your image tool!

Euro Driving Licence Photo Generator

(Free & Supports Bulk Upload)

Drag & drop your images here or

The result will appear here...
You can edit the below JavaScript code to customize the image tool.
function processImage(originalImg, outputMode = 'single', dpi = 300) {
    // Standard European Driving Licence photo dimensions: 35 mm x 45 mm
    const mmToInch = 25.4;
    
    // Validate and fallback parameters
    let parsedDpi = Number(dpi);
    if (isNaN(parsedDpi) || parsedDpi <= 0) parsedDpi = 300;
    
    let mode = (typeof outputMode === 'string') ? outputMode.trim().toLowerCase() : 'single';
    if (mode !== 'single' && mode !== 'print') mode = 'single';

    // Calculate exact pixel dimensions for 35x45mm at the specified DPI
    const photoWidthPx = Math.round((35 / mmToInch) * parsedDpi);
    const photoHeightPx = Math.round((45 / mmToInch) * parsedDpi);

    // 1. Create the single cropped Euro Licence Photo
    const photoCanvas = document.createElement('canvas');
    photoCanvas.width = photoWidthPx;
    photoCanvas.height = photoHeightPx;
    const ctx = photoCanvas.getContext('2d');
    
    // Fill white background in case of transparent images (like PNGs with no background)
    ctx.fillStyle = '#ffffff';
    ctx.fillRect(0, 0, photoWidthPx, photoHeightPx);

    // Smart Center Cropping Logic to match required aspect ratio
    const imgRatio = originalImg.width / originalImg.height;
    const targetRatio = photoWidthPx / photoHeightPx;
    
    let srcX = 0, srcY = 0;
    let srcW = originalImg.width, srcH = originalImg.height;
    
    if (imgRatio > targetRatio) {
        // Source image is wider than the target aspect ratio, crop the sides
        srcW = originalImg.height * targetRatio;
        srcX = (originalImg.width - srcW) / 2;
    } else {
        // Source image is taller than the target aspect ratio, crop top and bottom
        srcH = originalImg.width / targetRatio;
        // Shift focus by approx 15% towards the top, as faces in ID photos are usually upper-center
        srcY = (originalImg.height - srcH) * 0.15; 
    }
    
    // Draw and scale the cropped portion onto the photo canvas
    ctx.drawImage(originalImg, srcX, srcY, srcW, srcH, 0, 0, photoWidthPx, photoHeightPx);

    // Return the single standard photo if "single" mode is selected
    if (mode === 'single') {
        return photoCanvas;
    }

    // 2. Create a 4x6" Sheet with cut-guides for printing (if mode === 'print')
    const sheetCanvas = document.createElement('canvas');
    const sheetWidthPx = Math.round(4 * parsedDpi);   // 4 inches wide
    const sheetHeightPx = Math.round(6 * parsedDpi);  // 6 inches tall
    
    sheetCanvas.width = sheetWidthPx;
    sheetCanvas.height = sheetHeightPx;
    const pCtx = sheetCanvas.getContext('2d');

    // Fill standard white paper background
    pCtx.fillStyle = '#ffffff';
    pCtx.fillRect(0, 0, sheetWidthPx, sheetHeightPx);

    // Fit 6 photos perfectly onto a 4x6 inch paper (2 columns, 3 rows)
    const cols = 2;
    const rows = 3;
    
    const gridWidth = cols * photoWidthPx;
    const gridHeight = rows * photoHeightPx;
    
    // Space the photos evenly
    const gapX = (sheetWidthPx - gridWidth) / (cols + 1);
    const gapY = (sheetHeightPx - gridHeight) / (rows + 1);

    for (let r = 0; r < rows; r++) {
        for (let c = 0; c < cols; c++) {
            const x = Math.round(gapX + c * (photoWidthPx + gapX));
            const y = Math.round(gapY + r * (photoHeightPx + gapY));
            
            // Render the generated photo
            pCtx.drawImage(photoCanvas, x, y);
            
            // Draw subtle gray standard cut-lines
            pCtx.lineWidth = 1;
            pCtx.strokeStyle = '#cccccc';
            pCtx.strokeRect(x, y, photoWidthPx, photoHeightPx);
        }
    }
    
    return sheetCanvas;
}

Free Image Tool Creator

Can't find the image tool you're looking for?
Create one based on your own needs now!

Description

This tool is designed to automatically format personal photographs to meet the standard European driving licence requirements of 35mm x 45mm. It uses smart cropping logic to adjust the aspect ratio and can output a single high-resolution image or a print-ready 4×6 inch sheet containing multiple photos with cutting guides. This tool is useful for individuals needing to prepare official identification photos at home for driving licence applications or other European ID documents.

Leave a Reply

Your email address will not be published. Required fields are marked *