Please bookmark this page to avoid losing your image tool!

Image X-ray Photography Filter 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.
function processImage(originalImg) {
    // Create a new canvas element to draw the processed image on.
    const canvas = document.createElement('canvas');
    const ctx = canvas.getContext('2d');

    // Use naturalWidth and naturalHeight to get the original dimensions of the image,
    // in case the Image object's width/height properties are styled or not yet reflecting the loaded image's dimensions.
    const imgWidth = originalImg.naturalWidth || originalImg.width;
    const imgHeight = originalImg.naturalHeight || originalImg.height;

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

    // Draw the original image onto the canvas.
    // Note: If the image is from a different origin and lacks appropriate CORS headers,
    // this operation will "taint" the canvas. A tainted canvas will cause ctx.getImageData()
    // to throw a security error. The calling environment must ensure the Image object
    // is usable (e.g., by setting originalImg.crossOrigin = "Anonymous" before setting its src
    // if it's a cross-origin image from a server that provides CORS headers).
    ctx.drawImage(originalImg, 0, 0, imgWidth, imgHeight);

    // Get the pixel data from the canvas.
    // This returns an ImageData object containing a Uint8ClampedArray (data.data)
    // representing the pixel data in RGBA order.
    const imageData = ctx.getImageData(0, 0, imgWidth, imgHeight);
    const data = imageData.data; // Layout: [R1, G1, B1, A1, R2, G2, B2, A2, ...]

    // Iterate over each pixel in the image data.
    // We increment by 4 in each step because each pixel consists of 4 components (R, G, B, A).
    for (let i = 0; i < data.length; i += 4) {
        const r = data[i];     // Red component of the current pixel
        const g = data[i + 1]; // Green component
        const b = data[i + 2]; // Blue component
        // data[i + 3] is the Alpha component, which we will preserve.

        // Convert the pixel to grayscale using the luminosity method.
        // This formula gives a weighted average of R, G, B that better reflects human perception of brightness.
        // L = 0.299*R + 0.587*G + 0.114*B
        const gray = 0.299 * r + 0.587 * g + 0.114 * b;

        // Invert the grayscale value.
        // In an 8-bit color channel, color values range from 0 (black) to 255 (white).
        // Inverting swaps light and dark: new_value = 255 - old_value.
        const invertedGray = 255 - gray;

        // Set the R, G, and B components of the pixel to the new inverted grayscale value.
        data[i] = invertedGray;     // New Red value
        data[i + 1] = invertedGray; // New Green value
        data[i + 2] = invertedGray; // New Blue value
        // The Alpha value (data[i + 3]) remains unchanged to preserve any original transparency.
    }

    // Put the modified pixel data back onto the canvas.
    // This updates the canvas with the X-ray effect.
    ctx.putImageData(imageData, 0, 0);

    // Return the canvas element. The caller can then append this canvas to the DOM
    // or use it to generate a new image (e.g., canvas.toDataURL()).
    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 X-ray Photography Filter Effect Tool allows users to apply an X-ray filter effect to their images, transforming them to give a distinctive inverted grayscale appearance. This tool can be useful for creative purposes such as enhancing artistic projects, educational visuals, or providing a unique interpretation of photographs. Users can easily upload their images to see the transformed effect, allowing for experimentation in design or presentations.

Leave a Reply

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

Other Image Tools:

Image Radial Graduated Filter Effect Tool

Image Lee 80A Cooling Filter Effect Application

Image Autochrome Lumière Filter Effect Tool

Photo Infrared 720nm Filter Effect Tool

Image 10-Stop ND Filter Effect Tool

Photo Full Spectrum Filter Effect Tool

Image Motion Blur Filter Effect Tool

Image Panavision Film Look Filter Effect Tool

Image Rolleiflex TLR Camera Filter Effect Tool

Image Lee 85B Warming Filter Effect Application

Image Tiffen Black Pro-Mist Filter Effect Tool

Image Fomapan 100 Filter Effect Application

Image Lens Flare Filter Effect Tool

Image Ilford XP2 Super Filter Effect Application

Image Cinemascope Filter Effect Applicator

Image Dubblefilm Solar Filter Effect Application

Image Night Vision Filter Effect Tool

Image Tintype Filter Effect Application

Image Color Graduated Filter Effect Tool

Image Agfa Vista Filter Effect Application

Image Schneider Hollywood Black Magic Filter Effect Tool

Image TMax 400 Filter Effect Tool

Image Double Exposure Filter Effect Tool

Image Fujichrome Velvia 50 Filter Effect Application

Image Revolog Texture Film Filter Effect Tool

Image Lomography Metropolis Filter Effect Application

Image Variable ND Filter Effect Tool

Image 8mm Movie Film Filter Effect Application

Image TMax 100 Filter Effect Application

Image Fog Filter Effect Tool

Image Ektachrome E100 Filter Effect Application

Image RED Cinema Camera Filter Effect Tool

Image Reverse Graduated ND Filter Effect Tool

Image Kaleidoscope Filter Effect Tool

Image Platinum Palladium Print Filter Effect

Image Light Leak Filter Effect Tool

See All →