Please bookmark this page to avoid losing your image tool!

Image Side Blur Effect 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.
/**
 * Applies a blur effect to the left and right sides of an image.
 * The center of the image remains in focus.
 *
 * @param {HTMLImageElement} originalImg The original image object to process.
 * @param {number} blurAmount The radius of the blur in pixels. A larger value creates a more intense blur. Defaults to 10.
 * @param {number} sideWidthPercentage The width of each blurred side as a percentage of the total image width. For example, 20 means 20% on the left and 20% on the right will be blurred. Defaults to 20.
 * @returns {HTMLCanvasElement} A new canvas element with the side blur effect applied.
 */
function processImage(originalImg, blurAmount = 10, sideWidthPercentage = 20) {
    // Create a new canvas element
    const canvas = document.createElement('canvas');
    const ctx = canvas.getContext('2d');

    // Get the dimensions of the original image
    const width = originalImg.naturalWidth;
    const height = originalImg.naturalHeight;

    // Set the canvas dimensions to match the image
    canvas.width = width;
    canvas.height = height;

    // Sanitize input parameters to ensure they are valid numbers
    const validBlurAmount = Math.max(0, Number(blurAmount));
    const validSideWidthPercentage = Math.max(0, Math.min(50, Number(sideWidthPercentage)));

    // If there's no blur or the side width is zero, just draw the original image and return
    if (validBlurAmount === 0 || validSideWidthPercentage === 0) {
        ctx.drawImage(originalImg, 0, 0, width, height);
        return canvas;
    }

    // --- Main Logic: Draw the blurred background first, then the clear center ---

    // 1. Draw the entire image with a blur filter applied
    ctx.filter = `blur(${validBlurAmount}px)`;
    // To avoid blurred edges from leaking transparent pixels, we can draw the image slightly larger
    // and clipped, but for simplicity, a standard draw is often sufficient.
    ctx.drawImage(originalImg, 0, 0, width, height);

    // 2. Clear the filter for the next drawing operation
    ctx.filter = 'none';

    // 3. Calculate the dimensions of the central, non-blurred area
    const sideWidth = width * (validSideWidthPercentage / 100);
    const centerWidth = width - (2 * sideWidth);

    // 4. Draw the clear, central part of the original image on top of the blurred version
    if (centerWidth > 0) {
        ctx.drawImage(
            originalImg,      // Source image
            sideWidth,        // Source X
            0,                // Source Y
            centerWidth,      // Source Width
            height,           // Source Height
            sideWidth,        // Destination X
            0,                // Destination Y
            centerWidth,      // Destination Width
            height            // Destination Height
        );
    }
    
    // Return the final canvas
    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 Side Blur Effect Tool allows users to apply a blur effect to the left and right edges of an image, while keeping the center of the image in focus. Users can customize the intensity of the blur and the width of the blurred sides as a percentage of the image’s total width. This tool is useful for creating aesthetically pleasing visuals for social media posts, enhancing photography presentations, or designing graphics where the central subject needs to stand out against a softly blurred background.

Leave a Reply

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