Please bookmark this page to avoid losing your image tool!

Image To 20: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') {
    const targetRatio = 20 / 9;
    const w = originalImg.width;
    const h = originalImg.height;
    const currentRatio = w / h;

    let cw = w, ch = h;
    let sx = 0, sy = 0, sw = w, sh = h;
    let dx = 0, dy = 0, dw = w, dh = h;

    if (fitMode === 'contain' || fitMode === 'stretch') {
        if (currentRatio > targetRatio) {
            // Image is proportionally wider than 20:9. Base canvas on image width.
            cw = w;
            ch = w / targetRatio;
        } else {
            // Image is proportionally taller than 20:9. Base canvas on image height.
            ch = h;
            cw = h * targetRatio;
        }
        cw = Math.round(cw);
        ch = Math.round(ch);
        
        if (fitMode === 'contain') {
            // Keep original image size and center it to add padding (letterbox/pillarbox)
            dw = w;
            dh = h;
            dx = (cw - dw) / 2;
            dy = (ch - dh) / 2;
        } else {
            // Stretch the image entirely to fit the new canvas proportions
            dw = cw;
            dh = ch;
        }
    } else {
        // Default to 'cover' (crop bounding box to fit 20:9 without distorting)
        if (currentRatio > targetRatio) {
            // Image is too wide, crop the side edges
            ch = h;
            cw = h * targetRatio;
        } else {
            // Image is too tall, crop the top and bottom edges
            cw = w;
            ch = w / targetRatio;
        }
        cw = Math.round(cw);
        ch = Math.round(ch);
        
        // Isolate the central 20:9 crop portion of the original image
        sw = cw;
        sh = ch;
        sx = (w - sw) / 2;
        sy = (h - sh) / 2;
        dw = cw;
        dh = ch;
    }

    const canvas = document.createElement('canvas');
    canvas.width = cw;
    canvas.height = ch;
    const ctx = canvas.getContext('2d');

    // Apply background color to fill the padded areas if mode is 'contain'
    if (fitMode === 'contain' && backgroundColor !== 'transparent') {
        ctx.fillStyle = backgroundColor;
        ctx.fillRect(0, 0, canvas.width, canvas.height);
    }

    // Draw the image properly onto the prepared 20:9 canvas
    ctx.drawImage(originalImg, sx, sy, sw, sh, dx, dy, dw, dh);
    
    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 their images to a specific 20:9 aspect ratio. It provides multiple fitting options, including ‘cover’ to crop the image without distortion, ‘contain’ to show the full image with padding (letterboxing), and ‘stretch’ to expand the image to fill the new dimensions. It is particularly useful for content creators needing to format images for modern wide-screen smartphone displays, cinematic presentations, or specific social media requirements.

Leave a Reply

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