Please bookmark this page to avoid losing your image tool!

Image Line Eraser With Thickness And Direction Options

(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 horizontal or vertical lines from an image.
 *
 * @param {Image} originalImg The original image object to process.
 * @param {number} [thickness=2] The thickness in pixels of the lines to be erased. Must be 1 or greater.
 * @param {number} [linesToKeep=5] The number of pixel lines to keep between each erased line.
 * @param {string} [direction='horizontal'] The direction of the lines to erase. Accepts 'horizontal' or 'vertical'.
 * @returns {HTMLCanvasElement} A new canvas element with the lines erased.
 */
function processImage(originalImg, thickness = 2, linesToKeep = 5, direction = 'horizontal') {
    // Sanitize inputs
    const safeThickness = Math.max(1, Math.floor(thickness));
    const safeLinesToKeep = Math.max(0, Math.floor(linesToKeep));

    // Create a canvas element
    const canvas = document.createElement('canvas');
    const ctx = canvas.getContext('2d');

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

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

    // Set the composite operation to 'destination-out'.
    // This makes subsequent drawings "erase" pixels from the canvas, making them transparent.
    ctx.globalCompositeOperation = 'destination-out';
    ctx.fillStyle = 'rgba(0, 0, 0, 1)'; // Any opaque color will work for clearing

    const stepSize = safeLinesToKeep + safeThickness;

    // Avoid infinite loops if stepSize is invalid
    if (stepSize <= 0) {
        // Reset composite operation and return the canvas with just the original image
        ctx.globalCompositeOperation = 'source-over';
        return canvas;
    }

    // Check the direction and iterate to draw the erasing lines
    if (direction.toLowerCase() === 'vertical') {
        // Iterate through the width of the canvas
        for (let x = safeLinesToKeep; x < w; x += stepSize) {
            // Draw a vertical rectangle to erase a column of pixels
            ctx.fillRect(x, 0, safeThickness, h);
        }
    } else {
        // Default to horizontal
        // Iterate through the height of the canvas
        for (let y = safeLinesToKeep; y < h; y += stepSize) {
            // Draw a horizontal rectangle to erase a row of pixels
            ctx.fillRect(0, y, w, safeThickness);
        }
    }

    // Reset the composite operation to the default 'source-over' for future drawings
    ctx.globalCompositeOperation = 'source-over';

    // Return the modified canvas
    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 Line Eraser with Thickness and Direction Options tool allows users to remove specific horizontal or vertical lines from an image. Users can customize the thickness of the lines to be erased and specify how many pixel lines to keep between each erased line. This tool is particularly useful for cleaning up images that contain unwanted grid or line patterns, making it ideal for preparing images for presentations, creating clean backgrounds, or enhancing images for graphic design purposes.

Leave a Reply

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

Other Image Tools:

Image Transparent Line Editor

Image Line Eraser With Skip Options

Image Nth Line Eraser

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

See All →