Please bookmark this page to avoid losing your image tool!

Image Cokin Sunset Filter Effect Application

(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) {
    const canvas = document.createElement('canvas');
    // Using { willReadFrequently: true } can be an optimization hint for contexts
    // where getImageData/putImageData are used often. For a single pass, impact may be minor.
    const ctx = canvas.getContext('2d', { willReadFrequently: true });

    const imgWidth = originalImg.naturalWidth || originalImg.width;
    const imgHeight = originalImg.naturalHeight || originalImg.height;

    canvas.width = imgWidth;
    canvas.height = imgHeight;

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

    // If the image has no dimensions (e.g., not loaded or empty), return the empty canvas.
    if (imgWidth === 0 || imgHeight === 0) {
        return canvas;
    }

    const imageData = ctx.getImageData(0, 0, imgWidth, imgHeight);
    const data = imageData.data; // Uint8ClampedArray: [R,G,B,A, R,G,B,A, ...]

    // Parameters for the Cokin-style sunset filter effect.
    // These define the color transformation at its full strength.
    // These values are chosen to give a warm, orangey-red appearance.
    const fullEffectRedFactor = 1.4;   // Multiplicative factor for the red channel
    const fullEffectRedOffset = 40;    // Additive offset for the red channel
    const fullEffectGreenFactor = 1.15; // Multiplicative factor for the green channel
    const fullEffectGreenOffset = 20;   // Additive offset for the green channel (enhances yellow/orange hues)
    const fullEffectBlueFactor = 0.7;  // Multiplicative factor for the blue channel (dampens blue tones)
    // No specific additive offset for blue; the factor handles the reduction.

    // Graduation parameters:
    // This simulates a graduated filter, strongest at the top and fading out.
    // - Top 1/3 of the image: Full effect strength.
    // - Middle 1/3 of the image: Effect strength transitions linearly from full to none.
    // - Bottom 1/3 of the image: No effect.
    // These are typical proportions for a generic graduated filter.
    const fullEffectEndY = imgHeight / 3;
    const transitionEndY = 2 * imgHeight / 3;
    const transitionZoneHeight = transitionEndY - fullEffectEndY; // Conceptually, imgHeight / 3

    for (let i = 0; i < data.length; i += 4) {
        const r_orig = data[i];
        const g_orig = data[i+1];
        const b_orig = data[i+2];
        // Alpha channel (data[i+3]) is preserved.

        // Determine the y-coordinate of the current pixel
        const pixelIndex = i / 4;
        const y_pixel = Math.floor(pixelIndex / imgWidth);

        let strength_y = 0.0; // Effect strength for the current row (0.0 to 1.0)

        if (y_pixel < fullEffectEndY) {
            strength_y = 1.0; // Full effect
        } else if (y_pixel < transitionEndY) {
            // Linear transition in the middle zone
            // Guard against division by zero if transitionZoneHeight is 0 (e.g. imgHeight is extremely small, though imgHeight=0 is caught)
            if (transitionZoneHeight > 0.0001) { // Use a small epsilon for float comparison
                strength_y = 1.0 - (y_pixel - fullEffectEndY) / transitionZoneHeight;
            } else {
                // If no distinct transition zone, apply full strength if "above" midpoint, else none.
                // This case is rare for imgHeight >= 1.
                strength_y = (y_pixel < (fullEffectEndY + transitionEndY) / 2) ? 1.0 : 0.0;
            }
        } else {
            strength_y = 0.0; // No effect
        }
        
        // Optimization: if strength is effectively zero, the pixel colors don't change.
        if (strength_y < 0.001) { // Using a small epsilon for floating point comparison
            continue; 
        }

        // Calculate the target color values as if the filter applies with full strength
        const r_full_effect = r_orig * fullEffectRedFactor + fullEffectRedOffset;
        const g_full_effect = g_orig * fullEffectGreenFactor + fullEffectGreenOffset;
        const b_full_effect = b_orig * fullEffectBlueFactor;

        // Linearly interpolate between original color and full_effect color based on strength_y
        // newColor = originalColor * (1 - strength) + fullEffectColor * strength
        const newR = r_orig * (1 - strength_y) + r_full_effect * strength_y;
        const newG = g_orig * (1 - strength_y) + g_full_effect * strength_y;
        const newB = b_orig * (1 - strength_y) + b_full_effect * strength_y;

        // Clamp values to the [0, 255] range and assign back to the imageData array
        data[i]   = Math.max(0, Math.min(255, newR));
        data[i+1] = Math.max(0, Math.min(255, newG));
        data[i+2] = Math.max(0, Math.min(255, newB));
    }

    // Write the modified pixel data back to the canvas
    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 Cokin Sunset Filter Effect Application is a tool designed to enhance photographs by applying a creative color effect reminiscent of Cokin sunset filters. This tool modifies the image colors, intensifying reds and oranges while softening blue tones, simulating a warm and vibrant sunset ambiance. It features a graduated effect that is strongest at the top of the image and fades towards the bottom, making it ideal for landscape photography, travel photos, or any image where a pleasing, warm color enhancement is desired. Users can benefit from the tool when they want to add a dramatic touch to their images for sharing on social media, creating printed materials, or simply enhancing personal photo collections.

Leave a Reply

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

Other Image Tools:

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

Olympus OM-1 Photo Filter Effect Tool

Image Fujifilm Velvia Filter Effect Tool

Image Lensbaby Selective Focus Filter Effect Tool

Image Color Temperature Blue Filter Effect Tool

See All →