Please bookmark this page to avoid losing your image tool!

Image 3D Effect Creator

(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.
/**
 * Creates a 3D anaglyph effect on an image.
 * This effect works by separating the red and cyan color channels
 * and shifting them horizontally to create a sense of depth,
 * viewable with red/cyan 3D glasses.
 *
 * @param {HTMLImageElement} originalImg The original image object to process.
 * @param {number} [offset=10] The number of pixels to shift the color channels. A larger value creates a more pronounced 3D effect.
 * @returns {HTMLCanvasElement} A new canvas element with the 3D anaglyph effect applied.
 */
function processImage(originalImg, offset = 10) {
    const width = originalImg.naturalWidth;
    const height = originalImg.naturalHeight;

    // Create a canvas to draw the final result
    const canvas = document.createElement('canvas');
    canvas.width = width;
    canvas.height = height;
    const ctx = canvas.getContext('2d');

    // Create an offscreen canvas to get the original image's pixel data
    const offscreenCanvas = document.createElement('canvas');
    offscreenCanvas.width = width;
    offscreenCanvas.height = height;
    const offscreenCtx = offscreenCanvas.getContext('2d', { willReadFrequently: true });
    
    // Draw the original image to the offscreen canvas
    offscreenCtx.drawImage(originalImg, 0, 0);

    // Get the pixel data from the original image
    const originalImageData = offscreenCtx.getImageData(0, 0, width, height);
    const originalPixels = originalImageData.data;

    // Create a new ImageData object for the final 3D image
    const finalImageData = ctx.createImageData(width, height);
    const finalPixels = finalImageData.data;

    // Iterate over each pixel of the destination image
    for (let y = 0; y < height; y++) {
        for (let x = 0; x < width; x++) {
            const currentIndex = (y * width + x) * 4;

            // --- RED CHANNEL ---
            // Get the red channel from the original image, shifted "left"
            const redSourceX = x - offset;
            let redValue = 0;
            if (redSourceX >= 0) {
                const redSourceIndex = (y * width + redSourceX) * 4;
                redValue = originalPixels[redSourceIndex];
            }

            // --- CYAN (GREEN and BLUE) CHANNELS ---
            // Get the green and blue channels from the original image, shifted "right"
            const cyanSourceX = x + offset;
            let greenValue = 0;
            let blueValue = 0;
            if (cyanSourceX < width) {
                const cyanSourceIndex = (y * width + cyanSourceX) * 4;
                greenValue = originalPixels[cyanSourceIndex + 1];
                blueValue = originalPixels[cyanSourceIndex + 2];
            }
            
            // Get the alpha from the original pixel at the current location
            const alphaValue = originalPixels[currentIndex + 3];

            // Set the new pixel data in the final image
            finalPixels[currentIndex] = redValue;         // Red
            finalPixels[currentIndex + 1] = greenValue;   // Green
            finalPixels[currentIndex + 2] = blueValue;    // Blue
            finalPixels[currentIndex + 3] = alphaValue;   // Alpha
        }
    }

    // Put the modified pixel data onto the final canvas
    ctx.putImageData(finalImageData, 0, 0);

    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 3D Effect Creator is a web-based tool designed to enhance images by adding a 3D anaglyph effect. By separating the red and cyan color channels and applying horizontal shifts, this tool creates a sense of depth that can be viewed with red/cyan 3D glasses. This effect is useful for creating visually engaging images for presentations, enhancing photos for artistic purposes, or generating unique graphics for social media. Users can customize the intensity of the 3D effect by adjusting the offset value, making it suitable for various applications where an immersive visual experience is desired.

Leave a Reply

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