Skip to content

Commit c15c03a

Browse files
committed
Fix download functionality: Implement html2canvas for greeting card downloads
1 parent 2e5541e commit c15c03a

2 files changed

Lines changed: 34 additions & 3 deletions

File tree

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<link rel="stylesheet" href="styles.css">
88
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600;700&family=Dancing+Script:wght@400;700&display=swap" rel="stylesheet">
99
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
10+
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js"></script>
1011
</head>
1112
<body>
1213
<div class="container">

script.js

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,39 @@ class FriendshipGreetingApp {
316316
}
317317
}
318318

319-
downloadGreeting() {
320-
// In a real app, you would use html2canvas or similar library
321-
this.showNotification('Download feature would be implemented with html2canvas library!', 'info');
319+
async downloadCard() {
320+
try {
321+
const greetingCard = document.getElementById('greetingCard');
322+
323+
// Show loading notification
324+
this.showNotification('Generating your greeting card...', 'info');
325+
326+
// Configure html2canvas options
327+
const canvas = await html2canvas(greetingCard, {
328+
backgroundColor: null,
329+
scale: 2, // Higher quality
330+
useCORS: true,
331+
allowTaint: true,
332+
logging: false,
333+
width: greetingCard.offsetWidth,
334+
height: greetingCard.offsetHeight
335+
});
336+
337+
// Create download link
338+
const link = document.createElement('a');
339+
link.download = `friendship-greeting-${Date.now()}.png`;
340+
link.href = canvas.toDataURL('image/png');
341+
342+
// Trigger download
343+
document.body.appendChild(link);
344+
link.click();
345+
document.body.removeChild(link);
346+
347+
this.showNotification('Greeting card downloaded successfully!', 'success');
348+
} catch (error) {
349+
console.error('Download error:', error);
350+
this.showNotification('Failed to download greeting card. Please try again.', 'error');
351+
}
322352
}
323353

324354
shareGreeting() {

0 commit comments

Comments
 (0)