Please bookmark this page to avoid losing your image tool!

Image Cross-Screen Star 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 = 220,
    points = 4,
    radius = 50,
    color = "rgba(255, 255, 255, 0.8)",
    thickness = 1.5,
    angle = 0
) {
    // Coerce parameters to their expected types and validate them
    let p_brightnessThreshold = Number(String(brightnessThreshold));
    if (isNaN(p_brightnessThreshold)) {
        p_brightnessThreshold = 220; // Default if undefined or invalid
    }

    let p_points = parseInt(String(points), 10);
    if (isNaN(p_points) || p_points < 1) {
        p_points = 4; // Default if undefined, invalid, or less than 1
    }

    let p_radius = Number(String(radius));
    if (isNaN(p_radius)) {
        p_radius = 50; // Default if undefined or invalid
    }

    let p_thickness = Number(String(thickness));
    if (isNaN(p_thickness) || p_thickness <= 0) {
        p_thickness = 1.5; // Default if undefined, invalid, or non-positive
    }

    let p_angle = Number(String(angle));
    if (isNaN(p_angle)) {
        p_angle = 0; // Default if undefined or invalid
    }

    const p_color = String(color);

    const canvas = document.createElement('canvas');
    const ctx = canvas.getContext('2d');

    // Check if originalImg is a valid, loaded image object
    // naturalWidth/Height are 0 if not loaded or image is invalid.
    if (!originalImg || typeof originalImg.naturalWidth === 'undefined' || originalImg.naturalWidth === 0 || originalImg.naturalHeight === 0) {
        console.error("Original image is not loaded or invalid. Cannot apply star filter.");
        // Create a placeholder canvas with an error message
        canvas.width = 300;
        canvas.height = 150;
        ctx.fillStyle = "lightgray";
        ctx.fillRect(0, 0, canvas.width, canvas.height);
        ctx.fillStyle = "black";
        ctx.textAlign = "center";
        ctx.font = "16px Arial";
        ctx.fillText("Invalid Image Object", canvas.width / 2, canvas.height / 2);
        return canvas;
    }
    
    canvas.width = originalImg.naturalWidth;
    canvas.height = originalImg.naturalHeight;

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

    // Get image data. This can fail for cross-origin images if the canvas becomes tainted.
    let imageData;
    try {
        imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
    } catch (e) {
        console.error("Could not get image data (e.g., cross-origin issue):", e);
        // If image data cannot be accessed, return the canvas with the original image
        // and an error message drawn on top.
        ctx.fillStyle = "rgba(0, 0, 0, 0.6)";
        ctx.fillRect(0, 0, canvas.width, canvas.height);
        ctx.fillStyle = "white";
        ctx.textAlign = "center";
        ctx.font = "bold 16px Arial";
        ctx.fillText("Error: Cannot process cross-origin image.", canvas.width / 2, canvas.height / 2);
        return canvas;
    }
    const data = imageData.data;

    const brightSpots = [];

    // Iterate through pixels to find bright spots
    for (let i = 0; i < data.length; i += 4) {
        const r = data[i];
        const g = data[i + 1];
        const b = data[i + 2];
        
        // Calculate brightness using luma formula (perceived brightness)
        const brightness = 0.299 * r + 0.587 * g + 0.114 * b;

        if (brightness > p_brightnessThreshold) {
            const pixelIndex = i / 4;
            const x = pixelIndex % canvas.width;
            const y = Math.floor(pixelIndex / canvas.width);
            brightSpots.push({ x, y });
        }
    }

    // Set drawing properties for the stars
    ctx.strokeStyle = p_color;
    ctx.lineWidth = p_thickness;
    ctx.lineCap = 'round'; // Options: 'butt', 'round', 'square'

    const angleOffsetRad = (p_angle * Math.PI) / 180; // Convert offset angle to radians

    brightSpots.forEach(spot => {
        for (let i = 0; i < p_points; i++) {
            // Calculate the angle for the current spike
            const currentSpikeAngleRad = angleOffsetRad + (Math.PI * 2 * i) / p_points;
            
            // Calculate the end point of the spike
            // Spikes radiate from the center of the bright spot (spot.x, spot.y)
            const endX = spot.x + p_radius * Math.cos(currentSpikeAngleRad);
            const endY = spot.y + p_radius * Math.sin(currentSpikeAngleRad);
            
            // Draw the spike
            ctx.beginPath();
            ctx.moveTo(spot.x, spot.y);
            ctx.lineTo(endX, endY);
            ctx.stroke();
        }
    });

    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 Cross-Screen Star Filter Effect Tool allows users to enhance their images by applying a star filter effect to bright areas within the image. Users can customize various parameters such as brightness threshold, number of star points, radius of the star spikes, color, thickness, and angle of the stars. This tool is ideal for photographers and graphic designers looking to create visually striking effects, adding a professional touch to images for social media, presentations, or personal projects.

Leave a Reply

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

Other Image Tools:

Image Tiffen Ultra Contrast Filter Effect Application

Photo Telephoto Lens Compression Filter Effect Tool

Image Leica M6 Camera Render Filter Effect

Image Cokin Sunset Filter Effect Application

Image CineScope Aspect Ratio Filter Effect Tool

Image Ilford FP4 Plus Filter Effect Tool

Image Infrared 850nm Filter Effect Tool

Image Pentax 67 Medium Format Filter Effect Tool

Image ARRI Alexa Cinema Camera Filter Effect Enhancer

Image Cinestill 50D Filter Effect Application

Image Kodachrome 64 Filter Effect Tool

Photo Lomography Berlin Kino Filter Effect Tool

Image Fujifilm Neopan Filter Effect Tool

Image Polaroid Instant Film Filter Effect Tool

Image Holga Camera Filter Effect Tool

Image Fisheye Lens Distortion Filter Effect Tool

Image Kodak Gold 200 Film Filter Effect Tool

Photo Macro Filter Effect Tool

Image Neutral Density Filter Effect Tool

Image Green Filter Black And White Effect Tool

Image Large Format Film Filter Effect Creator

Image Pinhole Camera Filter Effect Tool

Image Warming Filter Effect Tool

Image Fujifilm Pro 400H Filter Effect Application

Image Diffusion Filter Effect Tool

Image Push-Processed Film Filter Effect Tool

Image Color Temperature Orange Filter Effect Tool

Image Kodak Ektar 100 Film Filter Effect

Image Yellow Filter Black And White Effect Tool

Image Expired Film Filter Effect Tool

Image Circular Polarizer Filter Effect Tool

Image Lomography Purple Filter Effect Tool

Image Split Field Filter Effect Tool

Image Soft Focus Filter Effect Tool

Image Medium Format Film Filter Effect

Image Wide-Angle Lens Perspective Filter Effect Tool

See All →