Please bookmark this page to avoid losing your image tool!

Image Gold Tone Filter

(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, strength = 0.85) {
    const canvas = document.createElement('canvas');
    // Use willReadFrequently for potential performance improvement if available/supported
    const ctx = canvas.getContext('2d', { willReadFrequently: true });

    // Ensure the image is loaded and has valid dimensions
    if (!originalImg.complete || originalImg.naturalWidth === 0 || originalImg.naturalHeight === 0) {
        console.error("Image is not fully loaded or has zero dimensions. Cannot process.");
        // Return an empty or minimal canvas to avoid further errors downstream
        canvas.width = 1; 
        canvas.height = 1;
        // Optionally, you could throw an error here:
        // throw new Error("Image is not fully loaded or has zero dimensions.");
        return canvas; 
    }

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

    ctx.drawImage(originalImg, 0, 0, canvas.width, canvas.height);

    const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
    const data = imageData.data; // Pixel data: [R,G,B,A, R,G,B,A, ...]

    // Clamp strength parameter to the range [0, 1]
    const mixFactor = Math.max(0, Math.min(1, Number(strength)));
    
    // Constants defining the gold tint characteristics
    const intensity = 1.3;   // Brightness factor for the gold color itself. >1 makes it brighter.
    const goldRBase = 1.0;   // Normalized R component for gold (e.g., 255/255)
    const goldGBase = 0.85;  // Normalized G component for gold (e.g., 215/255)
    const goldBBase = 0.30;  // Normalized B component for gold (e.g., 70/255, to add some depth and avoid pure yellow)

    for (let i = 0; i < data.length; i += 4) {
        const r = data[i];
        const g = data[i + 1];
        const b = data[i + 2];
        // Alpha channel (data[i+3]) will remain unchanged

        // Calculate luminance (perceived brightness/grayscale value)
        const gray = 0.299 * r + 0.587 * g + 0.114 * b;

        // Calculate the target gold-tinted color based on the grayscale value and intensity
        const tintedR = gray * goldRBase * intensity;
        const tintedG = gray * goldGBase * intensity;
        const tintedB = gray * goldBBase * intensity;

        // Blend the original color with the calculated gold-tinted color
        // The mixFactor (strength) determines how much of the gold tint is applied.
        // resultColor = (tintedColor * mixFactor) + (originalColor * (1 - mixFactor))
        data[i]   = Math.min(255, (tintedR * mixFactor) + (r * (1 - mixFactor)));
        data[i+1] = Math.min(255, (tintedG * mixFactor) + (g * (1 - mixFactor)));
        data[i+2] = Math.min(255, (tintedB * mixFactor) + (b * (1 - mixFactor)));
    }

    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 Gold Tone Filter tool applies a gold tint to images, allowing users to enhance their photos with a warm and luxurious color effect. This tool is ideal for photographers, graphic designers, and anyone looking to add a unique artistic touch to their images. Whether you’re creating elegant invitations, designing social media posts, or just exploring creative edits for personal photos, the gold tone filter can help make images stand out through a sophisticated color transformation.

Leave a Reply

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