Please bookmark this page to avoid losing your image tool!

Image To 12:9 Aspect Ratio Converter

(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, fitMode = "cover", backgroundColor = "#000000") {
    // Create canvas
    const canvas = document.createElement('canvas');
    const ctx = canvas.getContext('2d');

    // 12:9 is equivalent to 4:3
    const targetRatio = 12 / 9;
    
    const imgWidth = originalImg.width;
    const imgHeight = originalImg.height;
    const imgRatio = imgWidth / imgHeight;

    let canvasWidth, canvasHeight;
    let drawX = 0, drawY = 0, drawWidth = imgWidth, drawHeight = imgHeight;

    if (fitMode === "cover") {
        if (imgRatio > targetRatio) {
            // Image is wider than 12:9, crop the sides
            canvasHeight = imgHeight;
            canvasWidth = Math.round(imgHeight * targetRatio);
            drawWidth = canvasWidth;
            drawX = Math.round((imgWidth - canvasWidth) / 2);
            drawY = 0;
        } else {
            // Image is taller than 12:9, crop the top and bottom
            canvasWidth = imgWidth;
            canvasHeight = Math.round(imgWidth / targetRatio);
            drawHeight = canvasHeight;
            drawX = 0;
            drawY = Math.round((imgHeight - canvasHeight) / 2);
        }
        
        canvas.width = canvasWidth;
        canvas.height = canvasHeight;

        // Draw and crop the image
        ctx.drawImage(originalImg, drawX, drawY, drawWidth, drawHeight, 0, 0, canvasWidth, canvasHeight);
        
    } else {
        // fitMode is "contain" (adds padding to retain the full original image)
        if (imgRatio > targetRatio) {
            // Image is wider, pad the top and bottom
            canvasWidth = imgWidth;
            canvasHeight = Math.round(imgWidth / targetRatio);
            drawX = 0;
            drawY = Math.round((canvasHeight - imgHeight) / 2);
        } else {
            // Image is taller, pad the sides
            canvasHeight = imgHeight;
            canvasWidth = Math.round(imgHeight * targetRatio);
            drawX = Math.round((canvasWidth - imgWidth) / 2);
            drawY = 0;
        }
        
        canvas.width = canvasWidth;
        canvas.height = canvasHeight;

        // Fill background
        ctx.fillStyle = backgroundColor;
        ctx.fillRect(0, 0, canvasWidth, canvasHeight);

        // Draw the full image in the center
        ctx.drawImage(originalImg, 0, 0, imgWidth, imgHeight, drawX, drawY, imgWidth, imgHeight);
    }

    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

This tool allows users to convert images into a 12:9 aspect ratio (equivalent to 4:3). It offers two different processing modes: ‘cover,’ which crops the image to fill the entire frame, and ‘contain,’ which preserves the full original image by adding a customizable background color to fill the remaining space. This tool is useful for social media content creators, photographers, or designers who need to standardize their image dimensions for specific display requirements or digital platforms.

Leave a Reply

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