Please bookmark this page to avoid losing your image tool!

Image Blend Merger

(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.
async function processImage(originalImg, overlayImgSrc = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7', blendMode = 'normal', opacity = 1, offsetX = 0, offsetY = 0) {
    // Create a new canvas element
    const canvas = document.createElement('canvas');
    const ctx = canvas.getContext('2d');

    // Set canvas dimensions to match the original image
    canvas.width = originalImg.naturalWidth;
    canvas.height = originalImg.naturalHeight;

    // Draw the original (bottom) image onto the canvas
    ctx.drawImage(originalImg, 0, 0);

    // If there's no overlay image source, we can return early
    if (!overlayImgSrc || overlayImgSrc.trim() === '') {
        return canvas;
    }

    // Load the overlay (top) image
    const overlayImg = new Image();
    try {
        await new Promise((resolve, reject) => {
            // Set crossOrigin to "anonymous" to allow loading images from other domains without tainting the canvas
            overlayImg.crossOrigin = 'Anonymous';
            overlayImg.onload = resolve;
            overlayImg.onerror = (err) => reject(new Error('Failed to load the overlay image.'));
            overlayImg.src = overlayImgSrc;
        });
    } catch (error) {
        console.error(error);
        // If the overlay fails to load, return the canvas with just the original image
        return canvas;
    }

    // Save the current context state
    ctx.save();

    // Set the blending properties
    // Clamp opacity value between 0 and 1
    ctx.globalAlpha = Math.max(0, Math.min(1, opacity));

    // A list of valid blend modes for the 2D canvas context
    const validBlendModes = [
        'source-over', 'source-in', 'source-out', 'source-atop',
        'destination-over', 'destination-in', 'destination-out', 'destination-atop',
        'lighter', 'copy', 'xor', 'multiply', 'screen', 'overlay', 'darken',
        'lighten', 'color-dodge', 'color-burn', 'hard-light', 'soft-light',
        'difference', 'exclusion', 'hue', 'saturation', 'color', 'luminosity'
    ];
    // 'normal' is a common alias for 'source-over'
    if (blendMode === 'normal') {
        blendMode = 'source-over';
    }

    // Use the specified blend mode, or default to 'source-over' if invalid
    ctx.globalCompositeOperation = validBlendModes.includes(blendMode) ? blendMode : 'source-over';

    // Draw the overlay image on top of the original image with the specified offset
    ctx.drawImage(overlayImg, offsetX, offsetY);

    // Restore the context to its original state (resets globalAlpha and globalCompositeOperation)
    ctx.restore();

    // Return the final canvas with the merged images
    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

Image Blend Merger is an online tool that allows users to combine two images by overlaying one image on top of another using various blending modes and adjustable transparency. This tool can be useful for graphic designers, artists, or anyone looking to create customized images by merging elements together. Users can specify horizontal and vertical offsets for the overlay image, allowing precise positioning of the images. The available blend modes give users creative flexibility to produce visually appealing effects for personal, professional, or social media purposes.

Leave a Reply

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