Skip to content

Commit 78bf565

Browse files
committed
Improve image quality and enhance Create Your Own button with animations
1 parent 608a808 commit 78bf565

2 files changed

Lines changed: 126 additions & 6 deletions

File tree

script.js

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,46 @@ class FriendshipGreetingApp {
154154
const actionButtons = document.querySelector('.action-buttons');
155155
const createOwnBtn = document.createElement('button');
156156
createOwnBtn.id = 'createOwnBtn';
157-
createOwnBtn.className = 'action-btn';
158-
createOwnBtn.innerHTML = '<i class="fas fa-plus"></i> Create Your Own';
159-
createOwnBtn.style.background = '#667eea';
160-
createOwnBtn.style.color = 'white';
161-
createOwnBtn.style.border = '2px solid #667eea';
157+
createOwnBtn.className = 'create-own-btn';
158+
createOwnBtn.innerHTML = '<i class="fas fa-magic"></i> Create Your Own Greeting';
159+
160+
// Enhanced styling for full width and animations
161+
createOwnBtn.style.cssText = `
162+
width: 100%;
163+
padding: 18px 24px;
164+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
165+
color: white;
166+
border: none;
167+
border-radius: 15px;
168+
font-size: 18px;
169+
font-weight: 600;
170+
cursor: pointer;
171+
transition: all 0.3s ease;
172+
box-shadow: 0 8px 25px rgba(102, 126, 234, 0.3);
173+
animation: pulseGlow 2s infinite;
174+
margin-top: 20px;
175+
position: relative;
176+
overflow: hidden;
177+
`;
178+
179+
// Add hover effects
180+
createOwnBtn.addEventListener('mouseenter', () => {
181+
createOwnBtn.style.transform = 'translateY(-3px) scale(1.02)';
182+
createOwnBtn.style.boxShadow = '0 12px 35px rgba(102, 126, 234, 0.4)';
183+
});
184+
185+
createOwnBtn.addEventListener('mouseleave', () => {
186+
createOwnBtn.style.transform = 'translateY(0) scale(1)';
187+
createOwnBtn.style.boxShadow = '0 8px 25px rgba(102, 126, 234, 0.3)';
188+
});
162189

163190
createOwnBtn.addEventListener('click', () => {
191+
// Add click animation
192+
createOwnBtn.style.transform = 'scale(0.98)';
193+
setTimeout(() => {
194+
createOwnBtn.style.transform = 'scale(1)';
195+
}, 150);
196+
164197
// Remove the greeting parameter from URL and reload
165198
const url = new URL(window.location);
166199
url.searchParams.delete('greeting');
@@ -686,9 +719,14 @@ class FriendshipGreetingApp {
686719

687720
async uploadToImgBB(file) {
688721
const apiKey = '0ee3a371cdad624b9a1bacb8dc3c1696';
722+
723+
// Compress image if it's too large to maintain quality
724+
const compressedFile = await this.compressImage(file);
725+
689726
const formData = new FormData();
690727
formData.append('key', apiKey);
691-
formData.append('image', file);
728+
formData.append('image', compressedFile);
729+
formData.append('expiration', '15552000'); // 6 months in seconds
692730

693731
const response = await fetch('https://api.imgbb.com/1/upload', {
694732
method: 'POST',
@@ -706,6 +744,37 @@ class FriendshipGreetingApp {
706744
throw new Error('ImgBB upload failed');
707745
}
708746
}
747+
748+
async compressImage(file, maxWidth = 1920, maxHeight = 1080, quality = 0.9) {
749+
return new Promise((resolve) => {
750+
const canvas = document.createElement('canvas');
751+
const ctx = canvas.getContext('2d');
752+
const img = new Image();
753+
754+
img.onload = () => {
755+
// Calculate new dimensions while maintaining aspect ratio
756+
let { width, height } = img;
757+
758+
if (width > maxWidth || height > maxHeight) {
759+
const ratio = Math.min(maxWidth / width, maxHeight / height);
760+
width *= ratio;
761+
height *= ratio;
762+
}
763+
764+
canvas.width = width;
765+
canvas.height = height;
766+
767+
// Draw and compress
768+
ctx.drawImage(img, 0, 0, width, height);
769+
770+
canvas.toBlob((blob) => {
771+
resolve(blob);
772+
}, 'image/jpeg', quality);
773+
};
774+
775+
img.src = URL.createObjectURL(file);
776+
});
777+
}
709778
}
710779

711780
// Initialize the app when DOM is loaded

styles.css

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,32 @@ body {
351351
box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3);
352352
}
353353

354+
.create-own-btn {
355+
animation: popIn 0.6s ease-out;
356+
position: relative;
357+
overflow: hidden;
358+
}
359+
360+
.create-own-btn::before {
361+
content: '';
362+
position: absolute;
363+
top: 0;
364+
left: -100%;
365+
width: 100%;
366+
height: 100%;
367+
background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
368+
transition: left 0.5s;
369+
}
370+
371+
.create-own-btn:hover::before {
372+
left: 100%;
373+
}
374+
375+
.create-own-btn i {
376+
margin-right: 10px;
377+
animation: pulse 2s infinite;
378+
}
379+
354380
/* Animations */
355381
@keyframes fadeInDown {
356382
from {
@@ -403,6 +429,31 @@ body {
403429
}
404430
}
405431

432+
@keyframes pulseGlow {
433+
0%, 100% {
434+
box-shadow: 0 8px 25px rgba(102, 126, 234, 0.3);
435+
transform: scale(1);
436+
}
437+
50% {
438+
box-shadow: 0 12px 35px rgba(102, 126, 234, 0.5);
439+
transform: scale(1.02);
440+
}
441+
}
442+
443+
@keyframes popIn {
444+
0% {
445+
transform: scale(0.8);
446+
opacity: 0;
447+
}
448+
50% {
449+
transform: scale(1.1);
450+
}
451+
100% {
452+
transform: scale(1);
453+
opacity: 1;
454+
}
455+
}
456+
406457
@keyframes bounce {
407458
0%, 20%, 50%, 80%, 100% {
408459
transform: translateY(0);

0 commit comments

Comments
 (0)