Please bookmark this page to avoid losing your image tool!

Image Cloud Formation 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.
async function processImage(originalImg, noiseScale = 50, octaves = 4, persistence = 0.5, lacunarity = 2.0, effectStrength = 0.7) {

    // Helper to dynamically import SimplexNoise ES module from CDN
    // Caches the promise on the function object itself to ensure it's loaded only once.
    if (!processImage._simplexNoiseModulePromise) {
        processImage._simplexNoiseModulePromise = import('https://cdn.jsdelivr.net/npm/simplex-noise@4.0.1/dist/esm/simplex-noise.js')
            .catch(err => {
                processImage._simplexNoiseModulePromise = null; // Reset on failure to allow retry
                console.error("Failed to import SimplexNoise module:", err);
                // Throw a new error to make it clear that this is a loading issue specific to this function's needs
                throw new Error('Failed to load SimplexNoise library module. Please check your internet connection and ad-blockers. Error: ' + err.message);
            });
    }

    let SimplexNoiseConstructor;
    try {
        const simplexNoiseModule = await processImage._simplexNoiseModulePromise;
        SimplexNoiseConstructor = simplexNoiseModule.default; // Access the default export
        if (!SimplexNoiseConstructor) {
            throw new Error("SimplexNoise class not found in the imported module.");
        }
    } catch (error) {
        // Re-throw if already an error, or wrap if it's a new type of issue
        if (error instanceof Error) throw error;
        else throw new Error("Error obtaining SimplexNoise constructor: " + error);
    }
    
    const simplex = new SimplexNoiseConstructor(Math.random); // Initialize with a random seed

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

    // Draw the original image to the canvas
    ctx.drawImage(originalImg, 0, 0);

    // Get image data to manipulate pixels
    const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
    const data = imageData.data;

    // Normalize parameters to ensure they are within sensible ranges if needed
    effectStrength = Math.max(0, Math.min(1, effectStrength));
    noiseScale = Math.max(1, noiseScale); // Avoid division by zero or negative scale
    octaves = Math.max(1, Math.floor(octaves));
    persistence = Math.max(0.01, Math.min(1, persistence));
    lacunarity = Math.max(1.1, lacunarity);


    for (let y = 0; y < canvas.height; y++) {
        for (let x = 0; x < canvas.width; x++) {
            let noiseSample = 0;
            let currentFrequency = 1 / noiseScale;
            let currentAmplitude = 1;
            let maxAmplitude = 0;

            for (let i = 0; i < octaves; i++) {
                noiseSample += simplex.noise2D(x * currentFrequency, y * currentFrequency) * currentAmplitude;
                maxAmplitude += currentAmplitude;
                currentAmplitude *= persistence;
                currentFrequency *= lacunarity;
            }

            // Normalize noiseSample: simplex.noise2D returns [-1, 1]. FBM sum is [-maxAmplitude, maxAmplitude].
            // So, (noiseSample / maxAmplitude) is [-1, 1].
            // (+1)/2 maps it to [0, 1].
            const normalizedNoise = (noiseSample / maxAmplitude + 1) / 2;

            const idx = (y * canvas.width + x) * 4;
            const originalAlpha = data[idx + 3];

            // Calculate the alpha factor based on noise and effectStrength.
            // The formula f(n) = (1 - S) + n * S means:
            // - If effectStrength (S) is 0, f(n) = 1 (no change to alpha).
            // - If effectStrength (S) is 1, f(n) = n (alpha directly modulated by noise).
            // - If S is between 0 and 1, it's an interpolation.
            // This makes "cloudy" areas (high noise) more opaque, "clear" areas (low noise) more transparent.
            const alphaFactor = (1 - effectStrength) + normalizedNoise * effectStrength;
            
            data[idx + 3] = Math.max(0, Math.min(255, Math.floor(originalAlpha * alphaFactor)));
        }
    }

    // Put the modified image 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 Cloud Formation Filter Effect Tool allows users to apply a cloud-like effect to their images by utilizing noise generation techniques. This tool can be useful in various creative applications, such as enhancing visual aesthetics in graphic design, adding atmospheric textures to photos, or creating unique artistic effects in digital artwork. Users can adjust parameters like noise scale, octaves, persistence, lacunarity, and effect strength to customize the appearance of the cloud effect to match their specific needs.

Leave a Reply

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