Please bookmark this page to avoid losing your image tool!

Image Nth Line Eraser

(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.
/**
 * Erases every nth line of an image.
 *
 * @param {Image} originalImg The original image object to process.
 * @param {number} n The interval of lines to erase. For example, n=2 erases every 2nd line, n=3 erases every 3rd, etc. Must be a positive integer.
 * @returns {HTMLCanvasElement} A new canvas element with every nth line of the image erased (made transparent).
 */
function processImage(originalImg, n = 2) {
    // Create a canvas element to draw on
    const canvas = document.createElement('canvas');
    const ctx = canvas.getContext('2d');

    // Get the dimensions from 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;

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

    // Sanitize the 'n' parameter to ensure it's a positive integer
    const lineInterval = Math.floor(n);

    // If n is less than or equal to 1, there's nothing to process or the whole image is erased.
    // If n=1, erase the whole image. For n<=0, it's invalid, so we return the original.
    if (lineInterval <= 0) {
        console.error("The line interval 'n' must be a positive number.");
        return canvas; // Return the original image drawn on the canvas
    }
    if (lineInterval === 1) {
        ctx.clearRect(0, 0, width, height);
        return canvas; // Return a blank canvas
    }

    // Get the pixel data of the entire canvas
    const imageData = ctx.getImageData(0, 0, width, height);
    const data = imageData.data;

    // Iterate over each row of pixels
    for (let y = 0; y < height; y++) {
        // Check if the current row is an "nth" row (e.g., if n=3, check rows 2, 5, 8...)
        // We use (y + 1) because y is 0-indexed.
        if ((y + 1) % lineInterval === 0) {
            // If it is, iterate over each pixel in that row
            for (let x = 0; x < width; x++) {
                // Calculate the index of the pixel's alpha component in the data array.
                // Each pixel is represented by 4 values (R, G, B, A).
                const alphaIndex = (y * width + x) * 4 + 3;
                // Set the alpha value to 0 to make the pixel fully transparent.
                data[alphaIndex] = 0;
            }
        }
    }

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

    // Return the canvas with the modified image
    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 Nth Line Eraser is a tool designed to modify images by erasing every nth line, making those specific horizontal rows transparent. This functionality can be useful for creating unique visual effects, preparing images for artistic projects, or simplifying images for specific analyses. Users can easily specify the interval at which lines should be erased, enabling a range of creative applications, such as generating interesting patterns or reducing visual clutter in an image.

Leave a Reply

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

Other Image Tools:

Image To SVG Converter

Image Digitizer From Scan

Image Design for 10×4 Meter Landscape LED Screen with Running Video

Photo Custom Text Editor for Identification Cards

Image Outline Detection and Marking Tool

Image Diagonal Golden Ratio Overlay Tool

Image Line Drawer and Eraser

Image To Binary Converter For Optimized Storage

Image Japanese Anime Cell Shading Tool

Image Japanese Anime Cel Shading Renderer for Military Vehicles

Image Anime Cel Shade Effect Generator

Image Liquid Metallic Chrome Material Top View

Image Generator for Rainbow Six Siege Logo with Rainbow Fill

Image Transparency Adjuster for Clothing

Photo VHS Found Footage Analog Effect Tool

Image Old Fashioned Wanted Poster Creator

Image Toxic Waste Identifier

Image Realism Enhancer

Image Bulk Date and Location Stamp Adder Without Background Color

Image Time Stamp Removal Tool

Image Bulk Date and Text Stamp Adder

Image Bulk Date and Location Stamp Adder

Image Date and Location Stamp Adder

Image Date and Zone Stamping Tool

Image Bulk Date and Location Stamper

Image Bulk Date and Coordinate Stamper

Photo Artificial Metadata Generator

Photo Artificial Pattern Generator for Deepfake Bypass

Image Ultra Realistic Skin Texture Pore Emulation Tool

Image Chaotic Noise and Blur Generator for Deepfake Detection Evasion

Image Deep Effects Modification Tool

Image Portrait to Classic Hollywood Cinematic Still Enhancer

Image Chaotic Deep Modifications Editor

Image Chaotic Interleaving Modifier

Image Random Effects Generator with Low Intensity

Image Random Effects Generator

See All →