Please bookmark this page to avoid losing your image tool!

Image Hoya Pro ND 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, ndFactor = 64) {
    const canvas = document.createElement('canvas');
    
    // Handle cases where the originalImg might be null, undefined, or not yet loaded.
    // An Image object that is not loaded will have naturalWidth and naturalHeight of 0.
    if (!originalImg || typeof originalImg.naturalWidth === 'undefined' || typeof originalImg.naturalHeight === 'undefined') {
        // console.warn("processImage: originalImg is null, undefined, or not a proper Image object. Returning an empty 0x0 canvas.");
        canvas.width = 0;
        canvas.height = 0;
        return canvas;
    }

    canvas.width = originalImg.naturalWidth;
    canvas.height = originalImg.naturalHeight;
    
    const ctx = canvas.getContext('2d');
    if (!ctx) {
        // This should not happen in a standard browser environment for a 2D context.
        // console.error("processImage: Failed to get 2D context. Returning an empty canvas.");
        canvas.width = 0; // Ensure consistent empty canvas on critical failure.
        canvas.height = 0;
        return canvas;
    }

    // Draw the original image onto the canvas.
    // If the image isn't fully loaded, it might draw nothing or a broken icon, 
    // depending on browser and image state.
    try {
        ctx.drawImage(originalImg, 0, 0, canvas.width, canvas.height);
    } catch (e) {
        // console.error("processImage: Error drawing image to canvas.", e);
        // Return the canvas, which might be blank or partially drawn.
        return canvas;
    }
    
    // If either dimension of the canvas is zero (e.g., image not loaded or is genuinely 0-size),
    // getImageData will throw an error. In this scenario, we can't apply the filter.
    // So, we return the canvas with whatever drawImage managed to put on it.
    if (canvas.width === 0 || canvas.height === 0) {
        // console.warn("processImage: Image has zero width or height. Returning canvas without filter effect.");
        return canvas;
    }

    // Validate and parse the ndFactor.
    // An ND filter reduces light, so factor must be >= 1.
    let factor = parseFloat(ndFactor);
    if (isNaN(factor) || factor < 1) {
        // If factor is invalid (e.g., "abc", 0, or a negative number),
        // set it to 1, which means no darkening effect.
        factor = 1;
    }
    
    // If the factor is 1, it means no darkening effect is applied.
    // The original image is already drawn on the canvas, so we can return it directly.
    if (factor === 1) {
        return canvas;
    }

    // Get the pixel data from the canvas.
    // This can throw an error if the canvas is tainted (e.g. cross-origin image without CORS).
    let imageData;
    try {
        imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
    } catch (e) {
        // console.error("processImage: Failed to getImageData. Canvas might be tainted by cross-origin data.", e);
        // Return the canvas as-is, without the filter effect.
        return canvas;
    }
    
    const data = imageData.data; // data is a Uint8ClampedArray: [R, G, B, A, R, G, B, A, ...]

    // Iterate over each pixel in the imageData.
    // Each pixel consists of 4 components: Red, Green, Blue, Alpha.
    for (let i = 0; i < data.length; i += 4) {
        // Reduce the intensity of Red, Green, and Blue components by the ndFactor.
        // Math.round is used to convert the potentially floating-point result to an integer.
        data[i] = Math.round(data[i] / factor);     // Red component
        data[i + 1] = Math.round(data[i + 1] / factor); // Green component
        data[i + 2] = Math.round(data[i + 2] / factor); // Blue component
        // The Alpha component (data[i+3]) remains unchanged to preserve transparency.
    }

    // Put the modified pixel data back onto 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 Hoya Pro ND Filter Effect Application is a tool designed to simulate the use of a neutral density (ND) filter on images. By applying this effect, users can reduce the intensity of light in their images, which is particularly useful for photographers looking to create long exposure effects in bright conditions or achieve a shallow depth of field without overexposing their shots. This tool is valuable for both amateur and professional photographers who want to enhance their images or experiment with creative photography techniques.

Leave a Reply

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

Other Image Tools:

Image Wratten #12 Yellow Filter Effect Tool

Image AGFA APX 100 Film Filter Effect Tool

Image Singh-Ray Vari-ND Filter Effect Application

Image Rollei RPX 25 Film Filter Effect Tool

Image 35mm Half-frame Camera Filter Effect

Image Kodak Vision3 250D Motion Picture Film Effect Filter

Image 120 Film Format Filter Effect

Image Lens Whacking Filter Effect Tool

Image Black and White Red Filter Effect Tool

Image Lee Medium Stopper 6-Stop ND Filter Effect Tool

Image Nikon F3 Film Camera Render Effect Tool

Image Polaroid Spectra Filter Effect Tool

Image Contax T2/T3 Filter Effect Application

Image Bronica ETRS Medium Format Filter Effect Application

Image Soap Bubble Bokeh Effect Generator

Image Center Graduated ND Filter Effect Tool

Image Breakthrough Photography X4 ND Filter Effect

Photo Filter Effect Creator for Yashica T4 Point-and-Shoot

Image AGFA APX 25 Film Filter Effect Tool

Image Singh-Ray Gold-N-Blue Polarizer Effect Tool

Image Black and White Blue Filter Effect Tool

Image Pinhole Solargraphy Effect Creator

Image Kodak Vision3 500T Motion Picture Film Effect Simulator

Image Soft Focus Filter Effect for Nikon Nikkor

Image Bergger Pancro 400 Film Filter Effect Tool

Image Agfa Optima Filter Effect Application

Image Technicolor 3-Strip Process Filter Effect

Image Cyanotype Process Filter Effect

Image Black and White with Orange #21 Filter Effect Tool

Image Bleach Bypass Effect Filter

Image IMAX Camera Filter Effect Tool

Image Super 8 Film Filter Effect Tool

Image Anamorphic Lens Flare Filter Effect Tool

Image Prism Photography Filter Effect Tool

Image Freelensing Effect Creator

Image Tiffen Glimmerglass Filter Effect Tool

See All →