');
const previewContainer = document.getElementById('preview-container');
const canvas = document.getElementById('preview-canvas');
const ctx = canvas.getContext('2d');
const downloadBtn = document.getElementById('download-btn');
const baseImage = new Image();
baseImage.src = 'https://mynamefix.com/wp-content/uploads/2025/08/Wishing-you-all-the-best-on-your-special-day-and-throughout-the-year-ahead.png';
baseImage.onload = function() {
canvas.width = baseImage.width;
canvas.height = baseImage.height;
};
nameField.addEventListener('input', function() {
if (this.value.trim() !== "") {
previewContainer.style.display = 'block';
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.drawImage(baseImage, 0, 0, canvas.width, canvas.height);
ctx.font = "40px Amethysta";
ctx.fillStyle = "#d63434";
ctx.textAlign = "center";
ctx.fillText(this.value, canvas.width / 2, canvas.height / 2);
} else {
previewContainer.style.display = 'none';
}
});
downloadBtn.addEventListener('click', function() {
const link = document.createElement('a');
link.download = 'myname.png';
link.href = canvas.toDataURL('image/png');
link.click();
});
});