Please bookmark this page to avoid losing your image tool!

Image Chess Board 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, gridSize = 8, marginSize = 40, cropToSquare = "yes", lightSquareColor = "rgba(255, 255, 255, 0.2)", darkSquareColor = "rgba(0, 0, 0, 0.5)", marginColor = "#2b2b2b", textColor = "#ffffff") {
    gridSize = parseInt(gridSize) > 0 ? parseInt(gridSize) : 8;
    marginSize = parseInt(marginSize) >= 0 ? parseInt(marginSize) : 40;
    
    const canvas = document.createElement('canvas');
    const ctx = canvas.getContext('2d');

    let srcX = 0, srcY = 0, srcW = originalImg.width, srcH = originalImg.height;

    // Crop image to a perfect square if requested 
    // This is ideal since regular chessboards are perfect squares
    if (String(cropToSquare).toLowerCase() === "yes" || String(cropToSquare).toLowerCase() === "true") {
        const minDim = Math.min(originalImg.width, originalImg.height);
        srcX = (originalImg.width - minDim) / 2;
        srcY = (originalImg.height - minDim) / 2;
        srcW = minDim;
        srcH = minDim;
    }

    const boardW = srcW;
    const boardH = srcH;

    canvas.width = boardW + marginSize * 2;
    canvas.height = boardH + marginSize * 2;

    // Fill the outer boundary (margin area)
    ctx.fillStyle = marginColor;
    ctx.fillRect(0, 0, canvas.width, canvas.height);

    // Draw the original image onto the playable board area
    ctx.drawImage(originalImg, srcX, srcY, srcW, srcH, marginSize, marginSize, boardW, boardH);

    const cellW = boardW / gridSize;
    const cellH = boardH / gridSize;

    // Draw the chess grid overlay (semi-transparent checkerboard)
    for (let r = 0; r < gridSize; r++) {
        for (let c = 0; c < gridSize; c++) {
            // Standard chess convention has the top-left square (A8) as a light square
            if ((r + c) % 2 === 0) {
                ctx.fillStyle = lightSquareColor;
            } else {
                ctx.fillStyle = darkSquareColor;
            }
            ctx.fillRect(marginSize + c * cellW, marginSize + r * cellH, cellW, cellH);
        }
    }

    // Draw a border and rank/file coordinates if there is outer margin space
    if (marginSize > 0) {
        ctx.strokeStyle = textColor;
        ctx.lineWidth = Math.max(1, marginSize * 0.05);
        ctx.strokeRect(marginSize - ctx.lineWidth / 2, marginSize - ctx.lineWidth / 2, boardW + ctx.lineWidth, boardH + ctx.lineWidth);
    }

    if (marginSize >= 15) {
        ctx.fillStyle = textColor;
        ctx.textAlign = "center";
        ctx.textBaseline = "middle";
        const fontSize = Math.max(10, Math.min(marginSize * 0.4, 24));
        ctx.font = `bold ${fontSize}px sans-serif`;
        
        // Render File Coordinates (Letters at top and bottom margins)
        for (let c = 0; c < gridSize; c++) {
            let index = c % 26;
            let letter = String.fromCharCode(65 + index);
            if (c >= 26) {
                letter = String.fromCharCode(65 + Math.floor(c / 26) - 1) + letter;
            }
            ctx.fillText(letter, marginSize + c * cellW + cellW / 2, canvas.height - marginSize / 2);
            ctx.fillText(letter, marginSize + c * cellW + cellW / 2, marginSize / 2);
        }
        
        // Render Rank Coordinates (Numbers at left and right margins)
        for (let r = 0; r < gridSize; r++) {
            let number = (gridSize - r).toString();
            ctx.fillText(number, marginSize / 2, marginSize + r * cellH + cellH / 2);
            ctx.fillText(number, canvas.width - marginSize / 2, marginSize + r * cellH + cellH / 2);
        }
    }

    return canvas;
}

Free Image Tool Creator

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

Description

The Image Chess Board Generator allows you to overlay a customizable checkerboard grid onto any image. The tool can crop images into perfect squares, adjust the grid size, and modify the colors and transparency of the squares to create a semi-transparent overlay. It also features options to add margins with rank and file coordinates (letters and numbers), making it useful for creating custom chess-themed backgrounds, designing board game assets, or preparing images for use in tactical or educational chess applications.

Leave a Reply

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