You can edit the below JavaScript code to customize the image tool.
function processImage(originalImg, warmth = 0.4, contrast = 1.2, brightness = 5.0) {
// Parameter parsing and sanitization
// Default values from function signature are used if parameters are undefined.
// Convert to number and re-apply default if parsing results in NaN (e.g., if a non-numeric string was passed).
let numWarmth = parseFloat(warmth);
if (isNaN(numWarmth)) {
numWarmth = 0.4; // Default warmth if initial 'warmth' parameter was invalid
}
numWarmth = Math.max(0, Math.min(1, numWarmth)); // Clamp warmth: 0 (cool platinum-like) to 1 (warm palladium-like)
let numContrast = parseFloat(contrast);
if (isNaN(numContrast)) {
numContrast = 1.2; // Default contrast if initial 'contrast' parameter was invalid
}
// Allow contrast values from 0.1 (strong reduction) up to e.g. 3.0 (strong increase)
// Clamping numContrast to a positive value, e.g., Math.max(0.1, numContrast)
numContrast = Math.max(0.1, numContrast);
let numBrightness = parseFloat(brightness);
if (isNaN(numBrightness)) {
numBrightness = 5.0; // Default brightness adjustment if initial 'brightness' parameter was invalid
}
// numBrightness can be positive or negative. Clamping will occur at the pixel value level.
const canvas = document.createElement('canvas');
// Optimization hint for frequent read/write operations on the canvas context
const ctx = canvas.getContext('2d', { willReadFrequently: true });
// Use naturalWidth/Height if available (intrinsic image size), otherwise fall back to width/height
const imgWidth = originalImg.naturalWidth || originalImg.width;
const imgHeight = originalImg.naturalHeight || originalImg.height;
// Check for valid image dimensions
if (imgWidth === 0 || imgHeight === 0) {
console.warn("Image Platinum Palladium Print Filter: Original image has zero dimensions. Ensure the image is loaded before processing.");
// Return a 1x1 canvas to avoid errors with zero-dimension canvases in consuming code
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);
try {
// Get pixel data from the canvas
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
const data = imageData.data;
// Define base tinting factors for "Platinum" (cooler/neutral) and "Palladium" (warmer) characteristics
// These factors are applied to the grayscale pixel value L.
// Platinum end characteristics (generally cooler, more neutral, sometimes slightly bluish/cyan)
const rPtFactorBase = 0.98, gPtFactorBase = 0.99, bPtFactorBase = 1.00;
// Palladium end characteristics (generally warmer, brownish/sepia tones)
const rPdFactorBase = 1.00, gPdFactorBase = 0.92, bPdFactorBase = 0.85;
// Interpolate tint factors based on the 'warmth' parameter
const rTintFactor = (1 - numWarmth) * rPtFactorBase + numWarmth * rPdFactorBase;
const gTintFactor = (1 - numWarmth) * gPtFactorBase + numWarmth * gPdFactorBase;
const bTintFactor = (1 - numWarmth) * bPtFactorBase + numWarmth * bPdFactorBase;
// Iterate over each pixel (4 bytes: R, G, B, A)
for (let i = 0; i < data.length; i += 4) {
const r = data[i];
const g = data[i+1];
const b = data[i+2];
// 1. Convert to grayscale using the luminosity method (standard weights)
let L = 0.299 * r + 0.587 * g + 0.114 * b;
// 2. Apply contrast adjustment
// This formula scales pixel intensity relative to mid-gray (128)
L = numContrast * (L - 128) + 128;
// 3. Apply brightness adjustment
L = L + numBrightness;
// Clamp the modified grayscale value L to the valid range [0, 255]
L = Math.max(0, Math.min(255, L));
// 4. Apply the calculated Platinum/Palladium tint to the R, G, B channels
data[i] = Math.max(0, Math.min(255, L * rTintFactor)); // Red channel
data[i+1] = Math.max(0, Math.min(255, L * gTintFactor)); // Green channel
data[i+2] = Math.max(0, Math.min(255, L * bTintFactor)); // Blue channel
// Alpha channel (data[i+3]) is preserved
}
// Put the modified pixel data back onto the canvas
ctx.putImageData(imageData, 0, 0);
} catch (e) {
// Handle potential errors, e.g., if getImageData fails due to a tainted canvas (cross-origin image without CORS)
console.error("Image Platinum Palladium Print Filter: Error processing image data. This can occur with cross-origin images.", e);
// The canvas will contain the original image if processing failed after drawing it.
// Alternatively, one could re-throw the error or return null.
}
return canvas;
}
Free Image Tool Creator
Can't find the image tool you're looking for? Create one based on your own needs now!
The Image Platinum Palladium Print Filter Effect tool allows users to apply a unique visual effect to their images, mimicking the traditional platinum and palladium printing processes. Users can adjust the warmth, contrast, and brightness of their images, resulting in a dynamic range of tones that can appear cooler or warmer, depending on the selected settings. This tool is ideal for photographers and artists looking to enhance their images for artistic presentations, creating vintage or fine art effects, and for anyone who wishes to transform their digital images into works that evoke a specific aesthetic associated with classic printmaking techniques.