Update index.html
Browse files- index.html +69 -18
index.html
CHANGED
|
@@ -1,19 +1,70 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
</html>
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="ar" dir="rtl">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<title>تحويل صورة إلى نص - OCR</title>
|
| 6 |
+
<style>
|
| 7 |
+
body { font-family: Arial; margin: 40px; }
|
| 8 |
+
label, button { display: block; margin-top: 15px; }
|
| 9 |
+
#result { margin-top: 30px; background: #f5f5f5; padding: 20px; border-radius: 8px; min-height: 30px; }
|
| 10 |
+
</style>
|
| 11 |
+
</head>
|
| 12 |
+
<body>
|
| 13 |
+
<h2>تحويل صورة إلى نص (OCR)</h2>
|
| 14 |
+
<form id="ocr-form">
|
| 15 |
+
<label>اختر صورة:
|
| 16 |
+
<input type="file" id="image-input" accept="image/*" required>
|
| 17 |
+
</label>
|
| 18 |
+
<button type="submit">رفع وتحويل</button>
|
| 19 |
+
</form>
|
| 20 |
+
<div id="result"></div>
|
| 21 |
+
|
| 22 |
+
<script>
|
| 23 |
+
document.getElementById('ocr-form').addEventListener('submit', async function(event) {
|
| 24 |
+
event.preventDefault();
|
| 25 |
+
const resultDiv = document.getElementById('result');
|
| 26 |
+
resultDiv.textContent = "جاري التحويل...";
|
| 27 |
+
|
| 28 |
+
const fileInput = document.getElementById('image-input');
|
| 29 |
+
if (!fileInput.files.length) {
|
| 30 |
+
resultDiv.textContent = "اختر صورة أولاً.";
|
| 31 |
+
return;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
// تحويل الصورة إلى base64
|
| 35 |
+
const file = fileInput.files[0];
|
| 36 |
+
const reader = new FileReader();
|
| 37 |
+
reader.onload = async function() {
|
| 38 |
+
const base64Image = reader.result.split(',')[1]; // فقط الجزء base64
|
| 39 |
+
// تجهيز البيانات للإرسال
|
| 40 |
+
const params = new URLSearchParams();
|
| 41 |
+
params.append('image', base64Image);
|
| 42 |
+
params.append('language', 'ara'); // لو عايز لغة معينة غيرها (مثلاً eng, fra...)
|
| 43 |
+
|
| 44 |
+
try {
|
| 45 |
+
const response = await fetch('https://ocr-image-to-text-multilingual.p.rapidapi.com/imagetotext', {
|
| 46 |
+
method: 'POST',
|
| 47 |
+
headers: {
|
| 48 |
+
'x-rapidapi-key': '32769fb369mshfdf6f5e28e26674p1f3764jsn2a31085a1fc7',
|
| 49 |
+
'x-rapidapi-host': 'ocr-image-to-text-multilingual.p.rapidapi.com',
|
| 50 |
+
'Content-Type': 'application/x-www-form-urlencoded'
|
| 51 |
+
},
|
| 52 |
+
body: params
|
| 53 |
+
});
|
| 54 |
+
|
| 55 |
+
const data = await response.json();
|
| 56 |
+
// عرض النص الناتج
|
| 57 |
+
if (data.text) {
|
| 58 |
+
resultDiv.textContent = data.text;
|
| 59 |
+
} else {
|
| 60 |
+
resultDiv.textContent = "لم يتم التعرف على نص في الصورة.";
|
| 61 |
+
}
|
| 62 |
+
} catch (error) {
|
| 63 |
+
resultDiv.textContent = "حدث خطأ: " + error;
|
| 64 |
+
}
|
| 65 |
+
};
|
| 66 |
+
reader.readAsDataURL(file);
|
| 67 |
+
});
|
| 68 |
+
</script>
|
| 69 |
+
</body>
|
| 70 |
</html>
|