-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcloud.php
More file actions
198 lines (162 loc) · 8.35 KB
/
Copy pathcloud.php
File metadata and controls
198 lines (162 loc) · 8.35 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
<?php
session_start();
if (!isset($_SESSION['userid'])) {
header("Location:./signup.php");
}
require_once(__DIR__ . '/vendor/autoload.php');
require_once('./config.php');
// Configure API key authorization: Apikey
$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey("Apikey", $cloudmersive_key);
if (isset($_FILES['image'])) {
$file_name = $_FILES['image']['name'];
$file_size = $_FILES['image']['size'];
$file_tmp = $_FILES['image']['tmp_name'];
$file_type = $_FILES['image']['type'];
$string = explode('.', $_FILES['image']['name']);
$file_ext = strtolower(end($string));
$errors = array();
$extensions = array("jpg", "png", "jpeg");
$upload_link = "./uploads/" . $file_name;
if (in_array($file_ext, $extensions) === false) {
$errors[] = "extension not allowed, please choose a JPEG or PNG file.";
}
if ($file_size > 2097152) {
$errors[] = 'File size must not be more than 2 MB';
}
if (empty($errors) == true) {
move_uploaded_file($file_tmp, $upload_link);
$userid = $_SESSION['userid'];
$query1 = "INSERT INTO $dbname.convert(userid, name, piclink) values ($userid, '$file_name', '$upload_link')";
$result = mysqli_query($conn, $query1);
if ($result) {
// echo "Database entry done";
} else {
// echo "duplicate entry";
}
} else {
echo "Failure :(";
}
$apiInstance = new Swagger\Client\Api\ImageOcrApi(
new GuzzleHttp\Client(),
$config
);
$image_file = "./uploads/" . $file_name;
// print_r($image_file);
// $image_file = 'C:/Users/Netra/Downloads/notes1.jpeg';
// $image_file = 'D:/BHAGYASHREE/HACK/netra.jpeg'; // \SplFileObject | Image file to perform OCR on. Common file formats such as PNG, JPEG are supported.
$language = "ENG"; // string | Optional, language of the input document, default is English (ENG). Possible values are ENG (English), ARA (Arabic), ZHO (Chinese - Simplified), ZHO-HANT (Chinese - Traditional), ASM (Assamese), AFR (Afrikaans), AMH (Amharic), AZE (Azerbaijani), AZE-CYRL (Azerbaijani - Cyrillic), BEL (Belarusian), BEN (Bengali), BOD (Tibetan), BOS (Bosnian), BUL (Bulgarian), CAT (Catalan; Valencian), CEB (Cebuano), CES (Czech), CHR (Cherokee), CYM (Welsh), DAN (Danish), DEU (German), DZO (Dzongkha), ELL (Greek), ENM (Archaic/Middle English), EPO (Esperanto), EST (Estonian), EUS (Basque), FAS (Persian), FIN (Finnish), FRA (French), FRK (Frankish), FRM (Middle-French), GLE (Irish), GLG (Galician), GRC (Ancient Greek), HAT (Hatian), HEB (Hebrew), HIN (Hindi), HRV (Croatian), HUN (Hungarian), IKU (Inuktitut), IND (Indonesian), ISL (Icelandic), ITA (Italian), ITA-OLD (Old - Italian), JAV (Javanese), JPN (Japanese), KAN (Kannada), KAT (Georgian), KAT-OLD (Old-Georgian), KAZ (Kazakh), KHM (Central Khmer), KIR (Kirghiz), KOR (Korean), KUR (Kurdish), LAO (Lao), LAT (Latin), LAV (Latvian), LIT (Lithuanian), MAL (Malayalam), MAR (Marathi), MKD (Macedonian), MLT (Maltese), MSA (Malay), MYA (Burmese), NEP (Nepali), NLD (Dutch), NOR (Norwegian), ORI (Oriya), PAN (Panjabi), POL (Polish), POR (Portuguese), PUS (Pushto), RON (Romanian), RUS (Russian), SAN (Sanskrit), SIN (Sinhala), SLK (Slovak), SLV (Slovenian), SPA (Spanish), SPA-OLD (Old Spanish), SQI (Albanian), SRP (Serbian), SRP-LAT (Latin Serbian), SWA (Swahili), SWE (Swedish), SYR (Syriac), TAM (Tamil), TEL (Telugu), TGK (Tajik), TGL (Tagalog), THA (Thai), TIR (Tigrinya), TUR (Turkish), UIG (Uighur), UKR (Ukrainian), URD (Urdu), UZB (Uzbek), UZB-CYR (Cyrillic Uzbek), VIE (Vietnamese), YID (Yiddish)
$preprocessing = "Auto"; // string | Optional, preprocessing mode, default is 'Auto'. Possible values are None (no preprocessing of the image), and Auto (automatic image enhancement of the image before OCR is applied; this is recommended).
try {
$result = $apiInstance->imageOcrPost($image_file, $language, $preprocessing);
// print_r($result["text_result"]);
$final_result = explode(".", $result["text_result"]);
// print_r($final_result);
} catch (Exception $e) {
echo 'Exception when calling ImageOcrApi->imageOcrPost: ', $e->getMessage(), PHP_EOL;
}
// for ($count = 0; $count < sizeof($final_result); $count++) {
// print_r($final_result[$count]);
// echo "<br>";
// }
$result_file_path = "./results/" . $file_name . ".txt";
$result_file = fopen($result_file_path, "w");
fwrite($result_file, implode($final_result));
fclose($result_file);
print_r($result_file_path);
$userid = $_SESSION['userid'];
// $resultpath
$query2 = "UPDATE $dbname.convert set ogtext='" . $resultpath . $file_name . ".txt' WHERE name='$file_name'";
$result = mysqli_query($conn, $query2);
if ($result) {
// echo "Database entry done 2";
} else {
// echo "duplicate entry 2";
}
// $phpWord = new \PhpOffice\PhpWord\PhpWord();
// $section = $phpWord->addSection();
// $section->addText(implode($final_result));
// $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
// $objWriter->save('resultword.docx');
}
// if(isset($_POST['saveto'])){
// }
?>
<html>
<head>
<!-- Compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<link href="https://fonts.googleapis.com/css?family=Be+Vietnam&display=swap" rel="stylesheet">
<!-- Compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://code.responsivevoice.org/responsivevoice.js?key=KrEQqVp2"></script>
<style>
body {
font-family: 'Be Vietnam';
}
.nav-wrapper {
background-image: linear-gradient(to bottom right, #23416b, #b04276);
padding: 0px, 10px;
}
.card {
margin: 20px;
align: center;
}
.btn {
background-image: linear-gradient(to bottom right, #23416b, #b04276);
}
h4 {
color: black;
padding: 15px;
}
p {
color: black;
padding: 10px;
}
.input-field input[type="file"]:focus {
border-bottom: 1px linear-gradient(to bottom right, #23416b, #b04276);
}
</style>
</head>
<body>
<nav>
<div class="nav-wrapper">
<a href="#" class="brand-logo">NoteSync</a>
<ul id="nav-mobile" class="right hide-on-med-and-down">
<li><a href="./index.php">Home</a></li>
<li><a href="./userdocs.php">Your Docs</a></li>
<li><a style="float:right" href="#">Login</a></li>
</ul>
</div>
</nav>
<div class="row">
<div class="col s6 offset-s3">
<div class="card hoverable">
<div class="card-content white-text">
<span class="card-title"></span>
<h4 class="center">Getting Started With OCR</h4>
<h3>Your notes to text:</h3>
<div class="row">
<form class="col s12">
<div class="row">
<div class="input-field col s12">
<?php
$display_file = fopen("./results/" . $file_name . ".txt", "r");
?>
<textarea disabled id="textarea-ocr" class="materialize-textarea"><?php echo fread($display_file, 1000); ?></textarea>
<label for="textarea1"></label>
</div>
</div>
</form>
</div>
</form>
<a class="btn" href="./downloadtext.php?file=<?php echo $result_file_path; ?>">Download as text</a>
<a class="btn" href="./ocr.php">Try for another file</a>
<a class="btn" href="./tts.php">Convert to speech</a>
<a class="btn" href="./natlang.php">Get Wiki links</a>
</div>
</div>
</div>
</div>
</body>
</html>