Please bookmark this page to avoid losing your image tool!

Image Crop 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, startX = 0, startY = 0, cropWidth = 0, cropHeight = 0) {
    // Parse arguments to numbers, falling back to defaults if invalid
    let x = parseFloat(startX);
    if (isNaN(x)) x = 0;
    
    let y = parseFloat(startY);
    if (isNaN(y)) y = 0;
    
    let w = parseFloat(cropWidth);
    // If width is 0 or invalid, default to the remaining width of the image
    if (isNaN(w) || w <= 0) {
        w = originalImg.width - x;
    }
    
    let h = parseFloat(cropHeight);
    // If height is 0 or invalid, default to the remaining height of the image
    if (isNaN(h) || h <= 0) {
        h = originalImg.height - y;
    }

    // Clamp values to ensure they are within the actual image bounds
    x = Math.max(0, Math.min(x, originalImg.width - 1));
    y = Math.max(0, Math.min(y, originalImg.height - 1));
    w = Math.max(1, Math.min(w, originalImg.width - x));
    h = Math.max(1, Math.min(h, originalImg.height - y));

    // Create the output canvas
    const canvas = document.createElement('canvas');
    canvas.width = w;
    canvas.height = h;
    
    const ctx = canvas.getContext('2d');

    // Draw the cropped section onto the canvas
    ctx.drawImage(
        originalImg, 
        x, y, w, h,      // Source coordinates and dimensions
        0, 0, w, h       // Destination coordinates and dimensions
    );

    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 Crop Tool allows users to select and extract a specific rectangular section from an image. By defining starting coordinates and dimensions, the tool isolates the desired area and produces a new version of the image containing only that portion. This is useful for removing unwanted edges, focusing on specific subjects within a photo, or preparing images for specific layout requirements in social media, web design, or documentation.

Leave a Reply

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