Please bookmark this page to avoid losing your image tool!

Image Space Dust Filter Effect Creator

(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, dustColor = "rgba(255, 255, 255, 0.8)", dustDensity = 0.05, dustSizeMin = 1, dustSizeMax = 3) {
    const canvas = document.createElement('canvas');
    const ctx = canvas.getContext('2d');

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

    if (imgWidth === 0 || imgHeight === 0) {
        console.error("Image Space Dust Filter Effect: Original image has zero dimensions. Is it loaded correctly?");
        // Return a tiny, effectively empty canvas to avoid errors downstream.
        canvas.width = 1;
        canvas.height = 1;
        return canvas;
    }

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

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

    // --- Parameter Sanitization and Processing ---
    // Default values are set by the JavaScript engine if corresponding parameters are `undefined`.
    // This section validates and finalizes the parameters, handling cases like:
    // - Explicitly passed `null` or values of incorrect types (e.g., string for a number).
    // - Numeric values that are outside acceptable ranges (e.g., negative density).

    let finalDustColor;
    let finalDustDensity;
    let finalDustSizeMin;
    let finalDustSizeMax;

    // Validate dustColor: must be a non-empty string.
    if (typeof dustColor === 'string' && dustColor.trim() !== "") {
        finalDustColor = dustColor;
    } else {
        finalDustColor = "rgba(255, 255, 255, 0.8)"; // Default from signature
    }
    
    // Validate dustDensity: must be a non-negative number.
    const numDustDensity = Number(dustDensity); // Attempt to convert to number
    if (!isNaN(numDustDensity) && numDustDensity >= 0) {
        finalDustDensity = numDustDensity;
    } else {
        finalDustDensity = 0.05; // Default from signature
    }

    // Validate dustSizeMin: must be a positive number.
    const numDustSizeMin = Number(dustSizeMin); // Attempt to convert
    if (!isNaN(numDustSizeMin) && numDustSizeMin > 0) {
        finalDustSizeMin = numDustSizeMin;
    } else {
        finalDustSizeMin = 1; // Default from signature
    }

    // Validate dustSizeMax: must be a positive number.
    const numDustSizeMax = Number(dustSizeMax); // Attempt to convert
    if (!isNaN(numDustSizeMax) && numDustSizeMax > 0) {
        finalDustSizeMax = numDustSizeMax;
    } else {
        finalDustSizeMax = 3; // Default from signature
    }
    
    // Ensure min size is not greater than max size. If so, swap them.
    if (finalDustSizeMin > finalDustSizeMax) {
        [finalDustSizeMin, finalDustSizeMax] = [finalDustSizeMax, finalDustSizeMin];
    }
    // --- End Parameter Processing ---

    // Calculate the total number of dust particles based on density and image area.
    const numDustParticles = Math.floor(canvas.width * canvas.height * finalDustDensity);
    
    ctx.fillStyle = finalDustColor;

    for (let i = 0; i < numDustParticles; i++) {
        // Generate a random position for the dust particle
        const x = Math.random() * canvas.width;
        const y = Math.random() * canvas.height;
        
        // Generate a random size for the dust particle within the specified range.
        // Size is in [finalDustSizeMin, finalDustSizeMax).
        // If finalDustSizeMin equals finalDustSizeMax, particleSize will be exactly finalDustSizeMin.
        const particleSize = Math.random() * (finalDustSizeMax - finalDustSizeMin) + finalDustSizeMin;
        
        // Draw the dust particle (a small square).
        // Offset x and y by half the particle size to center the particle at (x, y).
        ctx.fillRect(x - particleSize / 2, y - particleSize / 2, particleSize, particleSize);
    }

    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 Space Dust Filter Effect Creator is a tool designed to add a dust particle effect to images, creating a stylized atmospheric appearance. Users can customize the color, density, and size of the dust particles to achieve desired visual effects. This tool is useful for enhancing photographs and graphics, adding depth or a dreamy quality to visuals. It can be used in various scenarios, such as digital art creation, photo editing for social media, or improving the aesthetic of website images.

Leave a Reply

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