Please bookmark this page to avoid losing your image tool!

Image Anamorphic Lens Flare 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,
    brightnessThreshold = 230,
    flareLength = 80,
    flareStrength = 0.7,
    flareColor = "120,180,255",
    flareMaxThickness = 2.0,
    flareSolidProportion = 0.1
) {
    const canvas = document.createElement('canvas');
    const ctx = canvas.getContext('2d');

    canvas.width = originalImg.naturalWidth || originalImg.width;
    canvas.height = originalImg.naturalHeight || originalImg.height;

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

    // 2. Get image data for pixel analysis
    // This needs to be done after drawing, as getImageData reads from the canvas content.
    let imageData;
    try {
        imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
    } catch (e) {
        console.error("Error getting image data: ", e);
        // If canvas is tainted (e.g., cross-origin image without CORS), we can't process.
        // In this case, we might just return the original image drawn on a new canvas,
        // or throw an error, or return an empty canvas.
        // For this example, let's return the canvas with just the original image drawn.
        return canvas;
    }
    
    const data = imageData.data;
    const width = canvas.width;
    const height = canvas.height;

    // Parse flare color string "R,G,B" into components
    const colorParts = flareColor.split(',');
    const flareR = parseInt(colorParts[0], 10) || 120;
    const flareG = parseInt(colorParts[1], 10) || 180;
    const flareB = parseInt(colorParts[2], 10) || 255;

    // 3. Iterate through each pixel to find bright spots and draw flares
    for (let y = 0; y < height; y++) {
        for (let x = 0; x < width; x++) {
            const i = (y * width + x) * 4; // Index for the R component of the current pixel
            const rVal = data[i];
            const gVal = data[i + 1];
            const bVal = data[i + 2];

            // Calculate luminance using the ITU-R BT.709 formula (perceived brightness)
            const luminance = 0.2126 * rVal + 0.7152 * gVal + 0.0722 * bVal;

            if (luminance > brightnessThreshold) {
                // Determine how much brighter the pixel is than the threshold (normalized 0-1)
                const effectiveMaxLuminanceAboveThreshold = Math.max(1, 255 - brightnessThreshold);
                const brightnessRatio = Math.min(1, (luminance - brightnessThreshold) / effectiveMaxLuminanceAboveThreshold);

                // Calculate flare properties based on brightnessRatio and input parameters
                // Flare length is influenced by base length, brightness, and overall strength
                const currentFlareLength = brightnessRatio * flareLength * (1 + flareStrength);
                
                // Peak opacity of the flare is influenced by brightness and strength
                const peakOpacity = brightnessRatio * flareStrength; 
                const clampedPeakOpacity = Math.min(1, Math.max(0, peakOpacity)); // Ensure opacity is [0,1]

                // Flare thickness scales with brightness up to flareMaxThickness
                const currentFlareThickness = Math.max(1, brightnessRatio * flareMaxThickness);
                
                // Only draw if the flare has some visible length, opacity, and thickness
                if (currentFlareLength > 1 && clampedPeakOpacity > 0.01 && currentFlareThickness >= 1) {
                    ctx.beginPath();
                    
                    // Align Y coordinate to pixel grid for sharper horizontal lines
                    const lineY = Math.floor(y) + 0.5; 
                    const startX = x - currentFlareLength / 2;
                    const endX = x + currentFlareLength / 2;

                    // Create a horizontal linear gradient for the flare's stroke style
                    const gradient = ctx.createLinearGradient(startX, lineY, endX, lineY);
                    
                    // Define gradient stops to create a flare that's brightest at the source
                    // and fades out towards its ends. flareSolidProportion controls the "core"
                    // of the flare that remains at peak opacity.
                    const coreStart = Math.max(0, 0.5 - (flareSolidProportion / 2));
                    const coreEnd = Math.min(1, 0.5 + (flareSolidProportion / 2));

                    gradient.addColorStop(0, `rgba(${flareR}, ${flareG}, ${flareB}, 0)`); // Start: fully transparent
                    if (coreStart === coreEnd) { // For a perfectly sharp peak (flareSolidProportion = 0)
                        gradient.addColorStop(coreStart, `rgba(${flareR}, ${flareG}, ${flareB}, ${clampedPeakOpacity})`);
                    } else {
                        gradient.addColorStop(coreStart, `rgba(${flareR}, ${flareG}, ${flareB}, ${clampedPeakOpacity})`);
                        gradient.addColorStop(coreEnd, `rgba(${flareR}, ${flareG}, ${flareB}, ${clampedPeakOpacity})`);
                    }
                    gradient.addColorStop(1, `rgba(${flareR}, ${flareG}, ${flareB}, 0)`); // End: fully transparent
                    
                    ctx.strokeStyle = gradient;
                    ctx.lineWidth = currentFlareThickness;
                    
                    // Draw the flare line
                    ctx.moveTo(startX, lineY);
                    ctx.lineTo(endX, lineY);
                    ctx.stroke();
                }
            }
        }
    }
    // Return the canvas with the original image and applied lens flares
    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 Anamorphic Lens Flare Filter Effect Tool allows users to apply lens flare effects to images, enhancing their visual appeal. This tool lets you customize various parameters such as the brightness threshold, flare length, strength, color, maximum thickness, and the solid proportion of the flare. It can be effectively used in photography and graphic design to create dramatic lighting effects, add a cinematic quality to images, or simulate the visual aesthetics often found in professional film and photography. Suitable for both personal and professional projects, this tool can serve creative needs in social media posts, art projects, and marketing materials.

Leave a Reply

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

Other Image Tools:

Image Prism Photography Filter Effect Tool

Image Freelensing Effect Creator

Image Tiffen Glimmerglass Filter Effect Tool

Image Mamiya RZ67 Medium Format Filter Effect Tool

Image Wet Plate Collodion Filter Effect Tool

Image Ilford Pan F Plus 50 Filter Effect Tool

Image X-ray Photography Filter Effect Tool

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

See All →