You can edit the below JavaScript code to customize the image tool.
Apply Changes
function processImage(originalImg, fogIntensity = "0.7", parchmentColor = "#ebdcc3", inkColor = "#3c2814") {
const width = originalImg.width;
const height = originalImg.height;
const canvas = document.createElement('canvas');
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext('2d');
// Draw original image to sample pixels
ctx.drawImage(originalImg, 0, 0);
const imgData = ctx.getImageData(0, 0, width, height);
const data = imgData.data;
// Helper: Hex to RGB
const hexToRgb = (hex) => {
hex = hex.replace(/^#/, '');
if(hex.length === 3) hex = hex.split('').map(c => c + c).join('');
const num = parseInt(hex, 16);
return [num >> 16, (num >> 8) & 255, num & 255];
};
const [pR, pG, pB] = hexToRgb(parchmentColor);
const [iR, iG, iB] = hexToRgb(inkColor);
// Precalculate grayscale values
const grays = new Float32Array(width * height);
for (let i = 0; i < width * height; i++) {
const idx = i * 4;
grays[i] = data[idx] * 0.299 + data[idx + 1] * 0.587 + data[idx + 2] * 0.114;
}
// Process map shading and edge detection
for (let y = 0; y < height; y++) {
for (let x = 0; x < width; x++) {
const i = y * width + x;
const idx = i * 4;
const gray = grays[i];
const grayR = x < width - 1 ? grays[i + 1] : gray;
const grayB = y < height - 1 ? grays[i + width] : gray;
// Simple edge detection pseudo-Sobel
const edge = Math.abs(gray - grayR) + Math.abs(gray - grayB);
const edgeFactor = Math.min(1, edge / 25);
// Base parchment shading based on terrain brightness
const shade = 0.55 + 0.45 * (gray / 255);
const noise = (Math.random() - 0.5) * 20;
let r = pR * shade + noise;
let g = pG * shade + noise;
let b = pB * shade + noise;
// Blend with map ink where edges outline "territory" contours
r = r * (1 - edgeFactor) + iR * edgeFactor;
g = g * (1 - edgeFactor) + iG * edgeFactor;
b = b * (1 - edgeFactor) + iB * edgeFactor;
data[idx] = r;
data[idx + 1] = g;
data[idx + 2] = b;
data[idx + 3] = 255;
}
}
// Apply the mapped terrain
ctx.putImageData(imgData, 0, 0);
// Draw Map Grid Lines
ctx.strokeStyle = `rgba(${iR}, ${iG}, ${iB}, 0.15)`;
ctx.lineWidth = Math.max(1, width * 0.002);
ctx.beginPath();
const gridSpacingX = width / 12;
const gridSpacingY = height / 12;
for (let x = gridSpacingX; x < width; x += gridSpacingX) {
ctx.moveTo(x, 0); ctx.lineTo(x, height);
}
for (let y = gridSpacingY; y < height; y += gridSpacingY) {
ctx.moveTo(0, y); ctx.lineTo(width, y);
}
ctx.stroke();
// Create the "Terra Incognita" Fog of War overlay
const fogAmt = Math.max(0, Math.min(1, parseFloat(fogIntensity)));
if (fogAmt > 0) {
const fogCanvas = document.createElement('canvas');
fogCanvas.width = width;
fogCanvas.height = height;
const fCtx = fogCanvas.getContext('2d');
// Fill solidly with parchment
fCtx.fillStyle = `rgb(${pR - 10}, ${pG - 10}, ${pB - 15})`;
fCtx.fillRect(0, 0, width, height);
// Punch out a viewing hole in the center
const cx = width / 2;
const cy = height / 2;
const maxRadius = Math.max(width, height) * (1.1 - fogAmt * 0.7);
const grad = fCtx.createRadialGradient(cx, cy, maxRadius * 0.15, cx, cy, maxRadius);
grad.addColorStop(0, 'rgba(0,0,0,1)'); // Completely clears fog in center
grad.addColorStop(0.6, 'rgba(0,0,0,0.7)');
grad.addColorStop(1, 'rgba(0,0,0,0)'); // Leaves fog opaque at edges
fCtx.globalCompositeOperation = 'destination-out';
fCtx.fillStyle = grad;
fCtx.fillRect(0, 0, width, height);
// Draw fog back onto main canvas
ctx.drawImage(fogCanvas, 0, 0);
}
// Apply vintage vignette (darkened burnt-style edges)
const cw = width / 2;
const ch = height / 2;
const vignetteRadius = Math.sqrt(cw * cw + ch * ch);
const vignetteGrad = ctx.createRadialGradient(cw, ch, vignetteRadius * 0.4, cw, ch, vignetteRadius * 1.2);
vignetteGrad.addColorStop(0, 'rgba(0, 0, 0, 0)');
vignetteGrad.addColorStop(1, `rgba(${Math.max(0, iR-20)}, ${Math.max(0, iG-20)}, ${Math.max(0, iB-20)}, 0.8)`);
ctx.fillStyle = vignetteGrad;
ctx.fillRect(0, 0, width, height);
// Draw the "TERRA INCOGNITA" text banner
ctx.fillStyle = `rgba(${iR}, ${iG}, ${iB}, 0.85)`;
const fontSize = Math.max(16, height * 0.05);
ctx.font = `bold ${fontSize}px Georgia, "Times New Roman", serif`;
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.letterSpacing = "6px"; // Modern canvas property
ctx.fillText("TERRA INCOGNITA", width / 2, height * 0.9);
ctx.letterSpacing = "0px";
// Draw an antique Compass Rose
const compassSize = Math.max(25, Math.min(width, height) * 0.08);
const compX = Math.max(compassSize * 2.5, width * 0.15);
const compY = Math.max(compassSize * 2.5, height * 0.15);
ctx.save();
ctx.translate(compX, compY);
ctx.lineJoin = "round";
// Compass Rings
ctx.strokeStyle = `rgba(${iR}, ${iG}, ${iB}, 0.7)`;
ctx.lineWidth = Math.max(1, compassSize * 0.03);
ctx.beginPath();
ctx.arc(0, 0, compassSize, 0, Math.PI * 2);
ctx.stroke();
ctx.beginPath();
ctx.arc(0, 0, compassSize * 0.85, 0, Math.PI * 2);
ctx.stroke();
// 4-Point Star
ctx.lineWidth = Math.max(1, compassSize * 0.02);
for(let k = 0; k < 4; k++) {
// Right shadow side
ctx.fillStyle = `rgba(${iR}, ${iG}, ${iB}, 0.9)`;
ctx.beginPath();
ctx.moveTo(0, -compassSize * 1.3);
ctx.lineTo(compassSize * 0.25, -compassSize * 0.25);
ctx.lineTo(0, 0);
ctx.fill();
// Left highlight side
ctx.fillStyle = `rgba(${pR}, ${pG}, ${pB}, 0.9)`;
ctx.beginPath();
ctx.moveTo(0, -compassSize * 1.3);
ctx.lineTo(-compassSize * 0.25, -compassSize * 0.25);
ctx.lineTo(0, 0);
ctx.fill();
// Outline entire point
ctx.beginPath();
ctx.moveTo(0, -compassSize * 1.3);
ctx.lineTo(compassSize * 0.25, -compassSize * 0.25);
ctx.lineTo(0, 0);
ctx.lineTo(-compassSize * 0.25, -compassSize * 0.25);
ctx.closePath();
ctx.stroke();
ctx.rotate(Math.PI / 2);
}
// Compass Directions N, E, S, W
ctx.fillStyle = `rgba(${iR}, ${iG}, ${iB}, 0.9)`;
ctx.font = `bold ${compassSize*0.5}px Georgia, "Times New Roman", serif`;
ctx.textBaseline = "middle";
ctx.textAlign = "center";
ctx.fillText("N", 0, -compassSize * 1.7);
ctx.fillText("S", 0, compassSize * 1.7);
ctx.fillText("E", compassSize * 1.7, 0);
ctx.fillText("W", -compassSize * 1.7, 0);
ctx.restore();
return canvas;
}
Apply Changes