Please bookmark this page to avoid losing your image tool!

Image Aspect Ratio Stretch To 21:9 Tool

(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, referenceDimension = "auto") {
    const canvas = document.createElement('canvas');
    const ctx = canvas.getContext('2d');

    const targetRatio = 21 / 9;
    const currentRatio = originalImg.width / originalImg.height;
    
    let newWidth, newHeight;

    // Determine new dimensions based on the chosen reference point
    if (referenceDimension === "width") {
        newWidth = originalImg.width;
        newHeight = Math.round(newWidth / targetRatio);
    } else if (referenceDimension === "height") {
        newHeight = originalImg.height;
        newWidth = Math.round(newHeight * targetRatio);
    } else {
        // "auto" mode: stretch the appropriate dimension strictly without shrinking the original bounds
        if (currentRatio > targetRatio) {
            // The image is wider than 21:9, so we keep the width and stretch out the height
            newWidth = originalImg.width;
            newHeight = Math.round(newWidth / targetRatio);
        } else {
            // The image is narrower than 21:9, so we keep the height and stretch out the width
            newHeight = originalImg.height;
            newWidth = Math.round(newHeight * targetRatio);
        }
    }

    // Set the explicitly calculated 21:9 canvas dimensions
    canvas.width = newWidth;
    canvas.height = newHeight;

    // Draw the image, which stretches it into the new 21:9 aspect ratio bounding box
    ctx.drawImage(originalImg, 0, 0, newWidth, newHeight);

    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 transform images into a 21:9 aspect ratio by stretching the original dimensions to fit the new widescreen format. Users can choose to adjust the image based on a specific width or height, or use the automatic mode to scale the image proportionally to reach the target ratio. This is particularly useful for creators preparing content for ultrawide monitors, cinematic presentations, or specific social media formats that require an ultra-wide aspect ratio.

Leave a Reply

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