Alhosiny commited on
Commit
5cbc0f2
·
verified ·
1 Parent(s): bbf57f9

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +30 -33
index.html CHANGED
@@ -94,22 +94,17 @@
94
  box-shadow: 0 4px 10px rgba(39, 174, 96, 0.2);
95
  }
96
 
97
- /* الكانفاس أصبح مخفياً دائماً، نحن نستخدمه للرسم فقط وليس للعرض */
98
  canvas {
99
  display: none !important;
100
  }
101
 
102
- /* هذا هو عنصر الصورة الحقيقية الذي سيتم عرضه للمستخدم */
103
  #finalImage {
104
  width: 100%;
105
  height: auto;
106
  margin-top: 25px;
107
  border-radius: 16px;
108
  box-shadow: 0 8px 16px rgba(0,0,0,0.1);
109
- display: none; /* مخفي حتى تكتمل الصورة */
110
- /* تحسينات اللمس للجوال */
111
- -webkit-user-select: none;
112
- user-select: none;
113
  }
114
 
115
  .hint {
@@ -131,17 +126,17 @@
131
  <button onclick="generateCard()">إنشاء البطاقة</button>
132
 
133
  <canvas id="myCanvas"></canvas>
134
-
135
  <img id="finalImage" alt="تهنئة رمضان لأسرة العصيل">
136
 
137
  <button id="downloadBtn" onclick="downloadImage()">تحميل الصورة</button>
138
- <p id="downloadHint" class="hint">ملاحظة: إذا لم يعمل زر التحميل، اضغط مطولاً على الصورة واختر "حفظ الصورة".</p>
139
  </div>
140
 
141
  <script>
142
  const canvas = document.getElementById('myCanvas');
143
  const ctx = canvas.getContext('2d');
144
  const image = new Image();
 
145
 
146
  image.crossOrigin = "Anonymous";
147
  image.src = 'template.jpg';
@@ -159,7 +154,7 @@
159
  return;
160
  }
161
 
162
- // 1. الرسم على الكانفاس المخفي
163
  ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
164
  ctx.font = "bold 80px 'Cairo'";
165
  ctx.fillStyle = "#000000";
@@ -168,34 +163,36 @@
168
  const yPosition = canvas.height - 350;
169
  ctx.fillText(name, xPosition, yPosition);
170
 
171
- // 2. تحويل الرسمة إلى صورة حقيقية وعرضها (هذا هو الحل لمشكلة التعليق!)
172
- const finalImage = document.getElementById('finalImage');
173
- finalImage.src = canvas.toDataURL("image/png");
174
- finalImage.style.display = "block";
 
 
 
 
 
 
175
 
176
- // إظهار الأزرار
177
- document.getElementById('downloadBtn').style.display = "block";
178
- document.getElementById('downloadHint').style.display = "block";
179
-
180
- // التمرير للأسفل
181
- setTimeout(() => {
182
- window.scrollTo({ top: document.body.scrollHeight, behavior: 'smooth' });
183
- }, 100);
184
  }
185
 
186
  function downloadImage() {
187
- // الآن نأخذ رابط التحميل من الصورة الحقيقية
188
- try {
189
- const finalImgSrc = document.getElementById('finalImage').src;
190
- const link = document.createElement('a');
191
- link.download = 'ramadan-mubarak.png';
192
- link.href = finalImgSrc;
193
- document.body.appendChild(link);
194
- link.click();
195
- document.body.removeChild(link);
196
- } catch (error) {
197
- alert("عذراً، متصفحك يمنع التحميل المباشر. يرجى الضغط مطولاً على الصورة واختيار 'حفظ الصورة'.");
198
- }
199
  }
200
  </script>
201
  </body>
 
94
  box-shadow: 0 4px 10px rgba(39, 174, 96, 0.2);
95
  }
96
 
 
97
  canvas {
98
  display: none !important;
99
  }
100
 
 
101
  #finalImage {
102
  width: 100%;
103
  height: auto;
104
  margin-top: 25px;
105
  border-radius: 16px;
106
  box-shadow: 0 8px 16px rgba(0,0,0,0.1);
107
+ display: none;
 
 
 
108
  }
109
 
110
  .hint {
 
126
  <button onclick="generateCard()">إنشاء البطاقة</button>
127
 
128
  <canvas id="myCanvas"></canvas>
 
129
  <img id="finalImage" alt="تهنئة رمضان لأسرة العصيل">
130
 
131
  <button id="downloadBtn" onclick="downloadImage()">تحميل الصورة</button>
132
+ <p id="downloadHint" class="hint">ملاحظة: إذا واجهت مشكلة، اختر "فتح الصورة بعلامة تبويب جديدة" ثم احفظها.</p>
133
  </div>
134
 
135
  <script>
136
  const canvas = document.getElementById('myCanvas');
137
  const ctx = canvas.getContext('2d');
138
  const image = new Image();
139
+ let imageBlobUrl = null; // متغير لحفظ رابط الملف الحقيقي
140
 
141
  image.crossOrigin = "Anonymous";
142
  image.src = 'template.jpg';
 
154
  return;
155
  }
156
 
157
+ // الرسم
158
  ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
159
  ctx.font = "bold 80px 'Cairo'";
160
  ctx.fillStyle = "#000000";
 
163
  const yPosition = canvas.height - 350;
164
  ctx.fillText(name, xPosition, yPosition);
165
 
166
+ // تحويل الرسمة إلى ملف حقيقي (Blob) لكي تعمل أزرار التحميل
167
+ canvas.toBlob(function(blob) {
168
+ if (imageBlobUrl) {
169
+ URL.revokeObjectURL(imageBlobUrl); // مسح الرابط القديم لعدم استهلاك الذاكرة
170
+ }
171
+ imageBlobUrl = URL.createObjectURL(blob);
172
+
173
+ const finalImg = document.getElementById('finalImage');
174
+ finalImg.src = imageBlobUrl;
175
+ finalImg.style.display = "block";
176
 
177
+ document.getElementById('downloadBtn').style.display = "block";
178
+ document.getElementById('downloadHint').style.display = "block";
179
+
180
+ setTimeout(() => {
181
+ window.scrollTo({ top: document.body.scrollHeight, behavior: 'smooth' });
182
+ }, 100);
183
+ }, 'image/png');
 
184
  }
185
 
186
  function downloadImage() {
187
+ if (!imageBlobUrl) return;
188
+
189
+ // إنشاء رابط تحميل مخفي والضغط عليه برمجياً
190
+ const link = document.createElement('a');
191
+ link.href = imageBlobUrl;
192
+ link.download = 'Ramadan-Mubarak.png';
193
+ document.body.appendChild(link);
194
+ link.click();
195
+ document.body.removeChild(link);
 
 
 
196
  }
197
  </script>
198
  </body>