Please bookmark this page to avoid losing your image tool!

Image Aspect Ratio Resizer To 9:16

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

    const w = originalImg.width;
    const h = originalImg.height;
    const orgRatio = w / h;
    
    // 9:16 aspect ratio
    const targetRatio = 9 / 16;

    let cWidth, cHeight;
    let dx = 0, dy = 0;

    // Determine canvas dimensions and image drawing offsets based on fit mode
    if (fitMode.toLowerCase() === "contain") {
        // Pad the image to fit 9:16 without losing any parts of the original image
        if (orgRatio > targetRatio) {
            // Image is proportionally wider than 9:16; we must pad top and bottom
            cWidth = w;
            cHeight = Math.round(w / targetRatio);
            dy = Math.round((cHeight - h) / 2);
        } else {
            // Image is proportionally taller than 9:16; we must pad left and right
            cHeight = h;
            cWidth = Math.round(h * targetRatio);
            dx = Math.round((cWidth - w) / 2);
        }
    } else {
        // Default mode is "cover" - crop the image to fill 9:16 completely
        if (orgRatio > targetRatio) {
            // Image is proportionally wider than 9:16; crop the left and right sides
            cHeight = h;
            cWidth = Math.round(h * targetRatio);
            dx = Math.round(-(w - cWidth) / 2);
        } else {
            // Image is proportionally taller than 9:16; crop the top and bottom sides
            cWidth = w;
            cHeight = Math.round(w / targetRatio);
            dy = Math.round(-(h - cHeight) / 2);
        }
    }

    // Prepare canvas sizes
    canvas.width = cWidth;
    canvas.height = cHeight;

    // Draw background color (visible mostly in 'contain' mode)
    ctx.fillStyle = backgroundColor;
    ctx.fillRect(0, 0, cWidth, cHeight);

    // Draw the image onto the canvas with calculated offsets
    ctx.drawImage(originalImg, dx, dy, w, h);

    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 quickly convert any image into a 9:16 aspect ratio, which is the standard format for vertical content. It offers two primary modes: ‘cover’, which crops the image to fill the entire frame, and ‘contain’, which pads the edges with a background color to ensure the entire original image remains visible. This is particularly useful for preparing photos for social media platforms like Instagram Stories, TikTok, or YouTube Shorts.

Leave a Reply

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