Please bookmark this page to avoid losing your image tool!

Image Amethyst Crystal 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, intensityStr = "0.6", rTintStr = "150", gTintStr = "80", bTintStr = "200", contrastStr = "1.1") {
    // Parse parameters and set defaults if parsing fails
    let intensity = parseFloat(intensityStr);
    if (isNaN(intensity)) intensity = 0.6;

    let rTint = parseInt(rTintStr, 10);
    if (isNaN(rTint)) rTint = 150;

    let gTint = parseInt(gTintStr, 10);
    if (isNaN(gTint)) gTint = 80;

    let bTint = parseInt(bTintStr, 10);
    if (isNaN(bTint)) bTint = 200;

    let contrast = parseFloat(contrastStr);
    if (isNaN(contrast)) contrast = 1.1;

    // Ensure the image is loaded before processing
    if (!originalImg.complete || originalImg.naturalWidth === 0) {
        // If the image is not loaded, wait for it to load
        await new Promise((resolve, reject) => {
            originalImg.onload = resolve;
            originalImg.onerror = (err) => {
                console.error("Error loading image:", err);
                reject(err); // Reject the promise if image loading fails
            };
            // If src is not set or loading has not started, reject (or handle as per requirement)
            // For this case, we assume src is set and it's trying to load or already loaded.
        });
    }
    
    if (originalImg.naturalWidth === 0 || originalImg.naturalHeight === 0) {
        console.error("Image has zero dimensions an_img.onload completed.");
        // Create a small empty canvas as a fallback or throw error
        const errorCanvas = document.createElement('canvas');
        errorCanvas.width = 1;
        errorCanvas.height = 1;
        return errorCanvas;
    }


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

    canvas.width = originalImg.naturalWidth;
    canvas.height = originalImg.naturalHeight;

    ctx.drawImage(originalImg, 0, 0);

    const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
    const data = imageData.data;

    for (let i = 0; i < data.length; i += 4) {
        let r = data[i];
        let g = data[i+1];
        let b = data[i+2];

        // Apply Amethyst Tint using linear interpolation
        let tintedR = r * (1 - intensity) + rTint * intensity;
        let tintedG = g * (1 - intensity) + gTint * intensity;
        let tintedB = b * (1 - intensity) + bTint * intensity;

        // Apply Contrast Boost
        // The contrast factor adjusts how much colors deviate from the midpoint (0.5 or 127.5)
        // A contrast of 1.0 means no change.
        if (contrast !== 1.0) {
            // Normalize to 0-1 range
            let normR = tintedR / 255.0;
            let normG = tintedG / 255.0;
            let normB = tintedB / 255.0;

            // Apply contrast: (value - 0.5) * factor + 0.5
            normR = (normR - 0.5) * contrast + 0.5;
            normG = (normG - 0.5) * contrast + 0.5;
            normB = (normB - 0.5) * contrast + 0.5;

            // Convert back to 0-255 range
            tintedR = normR * 255.0;
            tintedG = normG * 255.0;
            tintedB = normB * 255.0;
        }
        
        // Clamp values to the 0-255 range
        data[i]   = Math.max(0, Math.min(255, tintedR));
        data[i+1] = Math.max(0, Math.min(255, tintedG));
        data[i+2] = Math.max(0, Math.min(255, tintedB));
        // Alpha channel (data[i+3]) remains unchanged
    }

    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 Amethyst Crystal Filter Effect Tool allows users to apply a unique amethyst tint and enhance the contrast of their images. This tool is ideal for photographers, graphic designers, or social media users who wish to creatively alter their visuals for aesthetic purposes or branding. Users can adjust the tint intensity, customize the colors of the tint, and manipulate the image contrast to achieve the desired look. Use this tool to transform ordinary images into stunning visuals with a lovely amethyst effect.

Leave a Reply

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