Please bookmark this page to avoid losing your image tool!

Image Data Corruption 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.
async function processImage(originalImg, corruptionLevel = 20) {
    const canvas = document.createElement('canvas');
    const ctx = canvas.getContext('2d');
    const width = originalImg.width;
    const height = originalImg.height;

    canvas.width = width;
    canvas.height = height;
    ctx.drawImage(originalImg, 0, 0);

    if (corruptionLevel === 0 || width === 0 || height === 0) {
        return canvas;
    }

    // Normalize corruptionLevel to be 0-1 for internal calculations
    const level = corruptionLevel / 100;
    const random = Math.random; // Using built-in Math.random

    const imageData = ctx.getImageData(0, 0, width, height);
    const data = imageData.data; // Uint8ClampedArray [R,G,B,A,...]

    // Pre-allocate a buffer for row data manipulation if scanline glitches are possible
    const rowDataBuffer = (width > 0) ? new Uint8ClampedArray(width * 4) : null;

    // --- Effect 1: Horizontal Scanline Segment Shifting ---
    const numScanlineGlitchesFactor = 0.15; 
    const numScanlineGlitches = Math.floor(level * height * numScanlineGlitchesFactor);
    
    const maxScanlineShiftFactor = 0.3; 
    const actualMaxScanlineShift = Math.floor(width * maxScanlineShiftFactor * level);
    
    const maxGlitchHeightFactor = 0.08; 
    const actualMaxPossibleGlitchHeight = Math.max(1, Math.floor(height * maxGlitchHeightFactor * level));
    
    if (actualMaxScanlineShift > 0 && actualMaxPossibleGlitchHeight > 0 && rowDataBuffer) {
        for (let i = 0; i < numScanlineGlitches; i++) {
            const startY = Math.floor(random() * height);
            
            const currentGlitchMaxHeight = Math.min(actualMaxPossibleGlitchHeight, height - startY);
            if (currentGlitchMaxHeight <= 0) continue;
            
            const glitchH = Math.floor(random() * currentGlitchMaxHeight) + 1;
            
            const shiftAmount = Math.floor((random() - 0.5) * 2 * actualMaxScanlineShift);
            if (shiftAmount === 0) continue;

            for (let yOffset = 0; yOffset < glitchH; yOffset++) {
                const y = startY + yOffset;
                if (y >= height) continue; 

                const rowMemoryOffset = y * width * 4;
                
                // Read current row from main data into buffer
                for (let x = 0; x < width; x++) {
                    const currentPixelPosInData = rowMemoryOffset + x * 4;
                    rowDataBuffer[x * 4    ] = data[currentPixelPosInData    ];
                    rowDataBuffer[x * 4 + 1] = data[currentPixelPosInData + 1];
                    rowDataBuffer[x * 4 + 2] = data[currentPixelPosInData + 2];
                    rowDataBuffer[x * 4 + 3] = data[currentPixelPosInData + 3];
                }
                
                // Write shifted row from buffer back to main data
                for (let x = 0; x < width; x++) {
                    let sourceX = (x - shiftAmount);
                    sourceX = (sourceX % width + width) % width; // Wrap around
                    
                    const targetPixelPosInData = rowMemoryOffset + x * 4;
                    const sourcePixelPosInBuffer = sourceX * 4;

                    data[targetPixelPosInData    ] = rowDataBuffer[sourcePixelPosInBuffer    ];
                    data[targetPixelPosInData + 1] = rowDataBuffer[sourcePixelPosInBuffer + 1];
                    data[targetPixelPosInData + 2] = rowDataBuffer[sourcePixelPosInBuffer + 2];
                    data[targetPixelPosInData + 3] = rowDataBuffer[sourcePixelPosInBuffer + 3];
                }
            }
        }
    }

    // --- Effect 2: Dirty Block Copying ---
    const dirtyBlocksBaseCount = 30;
    const numDirtyBlocks = Math.floor(level * dirtyBlocksBaseCount);
    
    const maxBlockDimFactor = 0.15; 
    const actualMaxBlockDim = Math.max(1, Math.floor(Math.min(width, height) * maxBlockDimFactor * level));

    if (numDirtyBlocks > 0 && actualMaxBlockDim > 0) {
        for (let i = 0; i < numDirtyBlocks; i++) {
            const blockW = Math.floor(random() * actualMaxBlockDim) + 1;
            const blockH = Math.floor(random() * actualMaxBlockDim) + 1;

            if (blockW >= width || blockH >= height) continue; // Block is as large or larger than image

            const srcX = Math.floor(random() * (width - blockW));
            const srcY = Math.floor(random() * (height - blockH));
            const destX = Math.floor(random() * (width - blockW));
            const destY = Math.floor(random() * (height - blockH));

            for (let y = 0; y < blockH; y++) {
                for (let x = 0; x < blockW; x++) {
                    const srcIdx = ((srcY + y) * width + (srcX + x)) * 4;
                    const destIdx = ((destY + y) * width + (destX + x)) * 4;

                    data[destIdx    ] = data[srcIdx    ];
                    data[destIdx + 1] = data[srcIdx + 1];
                    data[destIdx + 2] = data[srcIdx + 2];
                    data[destIdx + 3] = data[srcIdx + 3]; // Copy alpha too for consistency
                }
            }
        }
    }
    
    // --- Effect 3: Random Pixel Color Channel Corruption ---
    const pixelCorruptionFactor = 0.02; // Max 2% of pixels affected
    const numPixelsToCorrupt = Math.floor(width * height * level * pixelCorruptionFactor);

    if (numPixelsToCorrupt > 0) {
        for (let i = 0; i < numPixelsToCorrupt; i++) {
            const pxX = Math.floor(random() * width);
            const pxY = Math.floor(random() * height);
            const pxIdx = (pxY * width + pxX) * 4;
            
            const channel = Math.floor(random() * 3); // 0 for R, 1 for G, 2 for B
            data[pxIdx + channel] = Math.floor(random() * 256); // Assign random value to one channel
        }
    }

    ctx.putImageData(imageData, 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 Data Corruption Filter Effect Tool allows users to apply various corruption effects to images, creating unique and distorted visual results. This tool can simulate glitches, scanline shifts, and random pixel corruption, making it ideal for artists, designers, and content creators looking to add a creative flair or vintage aesthetic to their digital images. Use cases include generating artwork, enhancing video game graphics, or creating social media content that stands out with refreshing and dynamic visual effects.

Leave a Reply

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