File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 ">
Original file line number Diff line number Diff 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 ( ) {
You can’t perform that action at this time.
0 commit comments