-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
236 lines (200 loc) · 8.13 KB
/
Copy pathindex.html
File metadata and controls
236 lines (200 loc) · 8.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>مولد بطاقات تهنئة العيد - مدرسة أم المؤمنين عائشة</title>
<link href="https://fonts.googleapis.com/css2?family=Cairo:wght@400;700&display=swap" rel="stylesheet">
<style>
:root {
--primary-color: #d6336c; /* مستوحى من لون زهور الصورة */
--bg-color: #fdf5e6; /* لون بيج هادئ */
--text-color: #4a4a4a;
}
body {
font-family: 'Cairo', sans-serif;
background-color: var(--bg-color);
margin: 0;
display: flex;
flex-direction: column;
align-items: center;
min-height: 100vh;
color: var(--text-color);
}
.container {
width: 90%;
max-width: 500px;
text-align: center;
padding: 20px;
margin-top: 20px;
background: white;
border-radius: 20px;
box-shadow: 0 10px 30px rgba(0,0,0,0.05);
}
h1 {
font-size: 1.5rem;
color: var(--primary-color);
margin-bottom: 20px;
}
/* حاوية العرض */
.card-preview {
position: relative;
width: 100%;
margin-bottom: 20px;
border-radius: 10px;
overflow: hidden;
box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}
canvas {
width: 100%; /* جعل الكانفاس متجاوب */
height: auto;
display: block;
}
/* منطقة الإدخال */
.controls {
display: flex;
flex-direction: column;
gap: 15px;
}
input[type="text"] {
padding: 12px;
border: 2px solid #eee;
border-radius: 10px;
font-family: 'Cairo', sans-serif;
font-size: 1.1rem;
text-align: center;
outline: none;
transition: border-color 0.3s;
}
input[type="text"]:focus {
border-color: var(--primary-color);
}
button {
padding: 12px;
background-color: var(--primary-color);
color: white;
border: none;
border-radius: 10px;
font-family: 'Cairo', sans-serif;
font-size: 1.1rem;
cursor: pointer;
transition: transform 0.2s, background 0.3s;
}
button:active {
transform: scale(0.95);
}
button:hover {
background-color: #b02a58;
}
/* التذييل */
footer {
margin-top: auto;
padding: 20px;
text-align: center;
font-size: 0.85rem;
color: #888;
}
footer a {
color: #25d366; /* لون واتساب */
text-decoration: none;
font-weight: bold;
}
/* لضمان التجاوب على الشاشات الصغيرة جداً */
@media (max-width: 400px) {
h1 { font-size: 1.2rem; }
input[type="text"], button { font-size: 0.95rem; }
}
</style>
</head>
<body>
<div class="container">
<h1> بطاقات العيد </h1>
<div class="card-preview">
<canvas id="cardCanvas"></canvas>
</div>
<div class="controls">
<input type="text" id="userName" placeholder="ضع إسمك هنا" maxlength="30">
<button id="downloadBtn"> تحميل البطاقة </button>
</div>
</div>
<footer>
<p>جميع الحقوق محفوظة لحروف © 2026</p>
<p>تواصل معنا واتساب: <a href="https://wa.me/966545782534" target="_blank">0552721966</a></p>
</footer>
<script>
const canvas = document.getElementById('cardCanvas');
const ctx = canvas.getContext('2d');
const nameInput = document.getElementById('userName');
const downloadBtn = document.getElementById('downloadBtn');
const cardImg = new Image();
cardImg.src = 'card.png'; // يجب أن يكون ملف الصورة بنفس الاسم في المجلد
// إحداثيات المستطيل الرمادي (تقديرية بناءً على تحليل الصورة)
// الصورة الأصلية تبدو عمودية (مثلاً 1000x1400)
// المستطيل يقع في العرض من 10% إلى 90%
// وفي الارتفاع (Y) يقع عند حوالي 76%
const rectConfig = {
centerXPercentage: 0.51, // توسيط أفقي بسيط للإزاحة البصرية
centerYPercentage: 0.79, // الارتفاع العمودي داخل المستطيل
maxWidthPercentage: 0.60 // أقصى عرض للنص لضمان عدم الخروج من الإطار
};
// التحقق من تحميل الصورة والخط
Promise.all([
new Promise(resolve => cardImg.onload = resolve),
document.fonts.load('bold 40px Cairo')
]).then(() => {
// ضبط أبعاد الكانفاس لتطابق الصورة الأصلية (للحفاظ على الجودة)
canvas.width = cardImg.width;
canvas.height = cardImg.height;
drawCard();
});
// وظيفة الرسم
function drawCard() {
const name = nameInput.value.trim();
// 1. رسم الصورة الأساسية
ctx.drawImage(cardImg, 0, 0, canvas.width, canvas.height);
if (name) {
// 2. إعدادات الخط
const x = canvas.width * rectConfig.centerXPercentage;
const y = canvas.height * rectConfig.centerYPercentage;
const maxWidth = canvas.width * rectConfig.maxWidthPercentage;
// حساب حجم الخط ديناميكياً (يبدأ من 60 وينقص حسب طول الاسم)
let fontSize = 60;
ctx.font = `bold ${fontSize}px Cairo`;
// تقليل حجم الخط إذا كان الاسم طويلاً
while (ctx.measureText(name).width > maxWidth && fontSize > 20) {
fontSize -= 2;
ctx.font = `bold ${fontSize}px Cairo`;
}
// 3. إضافة التنسيق (أبيض مع ظل خفيف)
ctx.fillStyle = '#b02a58';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
// إضافة ظل للنص لزيادة الوضوح
ctx.shadowColor = "rgba(0, 0, 0, 0.2)";
ctx.shadowBlur = 4;
ctx.shadowOffsetX = 2;
ctx.shadowOffsetY = 2;
// 4. طباعة الاسم
ctx.fillText(name, x, y);
// إعادة تعيين الظل لكي لا يؤثر على رسومات أخرى مستقبلاً
ctx.shadowBlur = 0;
ctx.shadowOffsetX = 0;
ctx.shadowOffsetY = 0;
}
}
// تحديث الرسم عند الكتابة
nameInput.addEventListener('input', drawCard);
// وظيفة التحميل
downloadBtn.addEventListener('click', () => {
if (!nameInput.value.trim()) {
alert('يرجى كتابة الاسم أولاً');
return;
}
const link = document.createElement('a');
link.download = `Eid-Card-${nameInput.value}.png`;
link.href = canvas.toDataURL('image/png', 1.0);
link.click();
});
</script>
</body>
</html>