Please bookmark this page to avoid losing your image tool!

Image Effects Naming 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.
/**
 * Applies a named visual effect to an image.
 *
 * @param {Image} originalImg The original javascript Image object to process.
 * @param {string} effectName The name of the effect to apply.
 *   Available effects: 'grayscale', 'sepia', 'invert', 'brighter', 'darker',
 *   'contrast', 'threshold', 'blur', 'saturate', 'hue-rotate'.
 *   If an unknown name is provided, the original image is returned. Defaults to 'grayscale'.
 * @returns {HTMLCanvasElement} A new canvas element with the applied effect.
 */
function processImage(originalImg, effectName = 'grayscale') {
    const canvas = document.createElement('canvas');
    const ctx = canvas.getContext('2d', { willReadFrequently: true });

    const w = originalImg.naturalWidth || originalImg.width;
    const h = originalImg.naturalHeight || originalImg.height;
    canvas.width = w;
    canvas.height = h;

    // Normalize effect name for case-insensitive matching
    const effect = effectName.toLowerCase();

    // Some effects can be applied easily using the built-in canvas filter property
    const filterEffects = {
        'blur': 'blur(4px)',
        'saturate': 'saturate(200%)',
        'hue-rotate': 'hue-rotate(90deg)'
    };

    if (filterEffects[effect]) {
        ctx.filter = filterEffects[effect];
        ctx.drawImage(originalImg, 0, 0);
        // Reset filter for subsequent draws on other contexts
        ctx.filter = 'none'; 
        return canvas;
    }

    // For other effects, we need to manipulate pixels manually
    ctx.drawImage(originalImg, 0, 0);
    
    // Check if the effect requires pixel manipulation, otherwise return the drawn canvas
    const requiresPixelManipulation = [
        'grayscale', 'sepia', 'invert', 'brighter', 'darker', 'contrast', 'threshold'
    ].includes(effect);

    if (!requiresPixelManipulation) {
        return canvas; // Return original image drawn on canvas for unknown effects
    }

    const imageData = ctx.getImageData(0, 0, w, h);
    const data = imageData.data;

    // Helper function to ensure color values stay within the 0-255 range
    const clamp = (value) => Math.max(0, Math.min(255, value));

    // Apply the selected effect pixel by pixel
    for (let i = 0; i < data.length; i += 4) {
        const r = data[i];
        const g = data[i + 1];
        const b = data[i + 2];

        switch (effect) {
            case 'grayscale':
                // Use luminosity method for better results than simple average
                const luminance = 0.299 * r + 0.587 * g + 0.114 * b;
                data[i] = data[i + 1] = data[i + 2] = luminance;
                break;
            case 'sepia':
                data[i] = clamp(r * 0.393 + g * 0.769 + b * 0.189);
                data[i + 1] = clamp(r * 0.349 + g * 0.686 + b * 0.168);
                data[i + 2] = clamp(r * 0.272 + g * 0.534 + b * 0.131);
                break;
            case 'invert':
                data[i] = 255 - r;
                data[i + 1] = 255 - g;
                data[i + 2] = 255 - b;
                break;
            case 'brighter':
                const brightnessAmount = 40;
                data[i] = clamp(r + brightnessAmount);
                data[i + 1] = clamp(g + brightnessAmount);
                data[i + 2] = clamp(b + brightnessAmount);
                break;
            case 'darker':
                const darknessAmount = 40;
                data[i] = clamp(r - darknessAmount);
                data[i + 1] = clamp(g - darknessAmount);
                data[i + 2] = clamp(b - darknessAmount);
                break;
            case 'contrast':
                const contrastAmount = 64; // Value in range [-255, 255]
                const factor = (259 * (contrastAmount + 255)) / (255 * (259 - contrastAmount));
                data[i] = clamp(factor * (r - 128) + 128);
                data[i + 1] = clamp(factor * (g - 128) + 128);
                data[i + 2] = clamp(factor * (b - 128) + 128);
                break;
             case 'threshold':
                const thresholdValue = 128;
                const thresholdLuminance = 0.299 * r + 0.587 * g + 0.114 * b;
                const value = thresholdLuminance > thresholdValue ? 255 : 0;
                data[i] = data[i + 1] = data[i + 2] = value;
                break;
        }
    }

    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 Effects Naming Tool allows users to apply various visual effects to images. It supports effects such as grayscale, sepia, inversion, brightness adjustments, contrast changes, and several filters like blur and saturation. This tool is ideal for enhancing images for social media posts, creating artistic effects for photography, or simply modifying images for personal projects. Users can easily select an effect by name, making it accessible for both casual and creative usage.

Leave a Reply

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