You can edit the below JavaScript code to customize the image tool.
Apply Changes
async function processImage(
originalImg,
text = "Happy Anniversary!",
years = 1,
bgColor = "#3a0a12",
accentColor = "#ffd700"
) {
// 1. Load an elegant font dynamically
try {
const font = new FontFace(
"Playfair Display",
"url(https://fonts.gstatic.com/s/playfairdisplay/v30/nuFvD-vYSZviVYUb_rj3ij__anPXJzDwcbmjWBN2PKdFvXDXbtM.woff2)"
);
const loadedFace = await font.load();
document.fonts.add(loadedFace);
} catch (e) {
console.warn("Could not load Google Font, falling back to system serif fonts.", e);
}
const fontFamily = "'Playfair Display', Georgia, serif";
// 2. Set dimensions with graceful scaling and margins
const maxDim = 900;
const minCanvasW = 600;
const scale = Math.min(1, maxDim / Math.max(originalImg.width, originalImg.height));
const imgW = originalImg.width * scale;
const imgH = originalImg.height * scale;
const paddingY = 220;
const paddingX = Math.max(140, (minCanvasW - imgW) / 2);
const canvas = document.createElement("canvas");
canvas.width = imgW + paddingX * 2;
canvas.height = imgH + paddingY * 2;
const ctx = canvas.getContext("2d");
// 3. Draw Background
ctx.fillStyle = bgColor;
ctx.fillRect(0, 0, canvas.width, canvas.height);
// 4. Draw Outer Borders (Ornate Vintage Styling)
ctx.strokeStyle = accentColor;
ctx.lineWidth = 2;
ctx.strokeRect(20, 20, canvas.width - 40, canvas.height - 40);
ctx.lineWidth = 1;
ctx.strokeRect(28, 28, canvas.width - 56, canvas.height - 56);
// Corner Flourishes
const drawCorner = (x, y, scaleX, scaleY, color) => {
ctx.save();
ctx.translate(x, y);
ctx.scale(scaleX, scaleY);
ctx.strokeStyle = color;
ctx.lineWidth = 3;
ctx.lineCap = "round";
ctx.lineJoin = "round";
ctx.beginPath();
ctx.moveTo(80, 0);
ctx.quadraticCurveTo(0, 0, 0, 80);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(65, 12);
ctx.quadraticCurveTo(12, 12, 12, 65);
ctx.stroke();
ctx.fillStyle = color;
ctx.beginPath();
ctx.arc(12, 12, 4, 0, Math.PI * 2);
ctx.fill();
ctx.restore();
};
drawCorner(28, 28, 1, 1, accentColor);
drawCorner(canvas.width - 28, 28, -1, 1, accentColor);
drawCorner(28, canvas.height - 28, 1, -1, accentColor);
drawCorner(canvas.width - 28, canvas.height - 28, -1, -1, accentColor);
// 5. Draw Image Matting (Frame around the picture)
ctx.save();
ctx.shadowColor = "rgba(0,0,0,0.7)";
ctx.shadowBlur = 20;
ctx.shadowOffsetX = 8;
ctx.shadowOffsetY = 8;
ctx.fillStyle = "#fffdf7"; // Warm gallery white
ctx.fillRect(paddingX - 20, paddingY - 20, imgW + 40, imgH + 40);
ctx.restore();
// Outer boundary of the mat
ctx.strokeStyle = accentColor;
ctx.lineWidth = 2;
ctx.strokeRect(paddingX - 24, paddingY - 24, imgW + 48, imgH + 48);
// Inner edge shadow/mat cut simulator
ctx.strokeStyle = "rgba(0,0,0,0.3)";
ctx.lineWidth = 1;
ctx.strokeRect(paddingX - 1, paddingY - 1, imgW + 2, imgH + 2);
// Draw Original Image
ctx.drawImage(originalImg, paddingX, paddingY, imgW, imgH);
// 6. Draw Decorations (Interlocking Rings and Sparkles at Top)
const drawRings = (cx, cy, radius, color) => {
ctx.save();
ctx.strokeStyle = color;
ctx.lineWidth = radius * 0.25;
ctx.shadowColor = "rgba(0,0,0,0.6)";
ctx.shadowBlur = 6;
ctx.shadowOffsetX = 2;
ctx.shadowOffsetY = 2;
ctx.beginPath(); // Left ring
ctx.arc(cx - radius * 0.6, cy, radius, 0, Math.PI * 2);
ctx.stroke();
ctx.beginPath(); // Right ring
ctx.arc(cx + radius * 0.6, cy + radius * 0.3, radius, 0, Math.PI * 2);
ctx.stroke();
// Shiny gem ring setting
const angle = Math.PI * 1.25;
const gemX = (cx - radius * 0.6) + Math.cos(angle) * radius;
const gemY = cy + Math.sin(angle) * radius;
ctx.beginPath();
ctx.arc(gemX, gemY, radius * 0.35, 0, Math.PI * 2);
ctx.fillStyle = "#ffffff";
ctx.shadowColor = "#ffffff";
ctx.shadowBlur = 15;
ctx.shadowOffsetX = 0;
ctx.shadowOffsetY = 0;
ctx.fill();
ctx.restore();
};
const drawSparkle = (sx, sy, size, color) => {
ctx.save();
ctx.translate(sx, sy);
ctx.fillStyle = color;
ctx.beginPath();
ctx.moveTo(0, -size);
ctx.quadraticCurveTo(0, 0, size, 0);
ctx.quadraticCurveTo(0, 0, 0, size);
ctx.quadraticCurveTo(0, 0, -size, 0);
ctx.closePath();
ctx.fill();
ctx.restore();
};
const ringsY = 90;
drawRings(canvas.width / 2, ringsY, 25, accentColor);
drawSparkle(canvas.width / 2 - 50, ringsY - 20, 10, accentColor);
drawSparkle(canvas.width / 2 + 55, ringsY - 30, 14, accentColor);
drawSparkle(canvas.width / 2 + 10, ringsY + 25, 8, accentColor);
// 7. Typography Details
ctx.fillStyle = accentColor;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
const fitText = (textStr, maxW, initialSize) => {
let size = initialSize;
ctx.font = `italic 700 ${size}px ${fontFamily}`;
while (ctx.measureText(textStr).width > maxW && size > 16) {
size -= 2;
ctx.font = `italic 700 ${size}px ${fontFamily}`;
}
return size;
};
// Format Years String (Top Text)
let parsedYear = parseInt(years);
let topText = "Anniversary";
if (!isNaN(parsedYear) && parsedYear > 0) {
const j = parsedYear % 10, k = parsedYear % 100;
let suffix = "th";
if (j === 1 && k !== 11) suffix = "st";
else if (j === 2 && k !== 12) suffix = "nd";
else if (j === 3 && k !== 13) suffix = "rd";
topText = `${parsedYear}${suffix} Anniversary`;
} else if (typeof years === "string" && years.trim() !== "") {
topText = `${years} Anniversary`;
}
// Draw Top Text
fitText(topText, canvas.width - paddingX, 45);
ctx.fillText(topText, canvas.width / 2, 160);
// Draw Bottom Custom Text
fitText(text, canvas.width - paddingX, 55);
ctx.fillText(text, canvas.width / 2, canvas.height - 120);
// 8. Draw Decorative Bottom Heart
const drawHeart = (hx, hy, width, height, fillStyle) => {
ctx.save();
ctx.beginPath();
let topCurveHeight = height * 0.3;
ctx.moveTo(hx, hy + topCurveHeight);
ctx.bezierCurveTo(hx, hy, hx - width / 2, hy, hx - width / 2, hy + topCurveHeight);
ctx.bezierCurveTo(hx - width / 2, hy + (height + topCurveHeight) / 2, hx, hy + (height + topCurveHeight) / 2, hx, hy + height);
ctx.bezierCurveTo(hx, hy + (height + topCurveHeight) / 2, hx + width / 2, hy + (height + topCurveHeight) / 2, hx + width / 2, hy + topCurveHeight);
ctx.bezierCurveTo(hx + width / 2, hy, hx, hy, hx, hy + topCurveHeight);
ctx.closePath();
ctx.shadowColor = "rgba(0,0,0,0.5)";
ctx.shadowBlur = 5;
ctx.shadowOffsetY = 2;
ctx.fillStyle = fillStyle;
ctx.fill();
ctx.restore();
};
drawHeart(canvas.width / 2, canvas.height - 75, 28, 28, accentColor);
return canvas;
}
Apply Changes