-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
7 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
<meta http-equiv="X-UA-Compatible" content="ie=edge" /> | ||
<title>File Reader API</title> | ||
<link rel="stylesheet" href="css/style.css" /> | ||
<script type="module" src="js/index.js" defer></script> | ||
</head> | ||
<body> | ||
<input type="file" /> | ||
|
@@ -15,7 +16,5 @@ | |
<div class="ocr-result"> | ||
<p></p> | ||
</div> | ||
<script src="https://cdn.jsdelivr.net/gh/naptha/[email protected]/dist/tesseract.min.js"></script> | ||
<script src="js/index.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
'use strict' | ||
import { createWorker } from 'https://cdn.jsdelivr.net/npm/[email protected]/+esm' | ||
|
||
const inputFile = document.querySelector('input') | ||
const preview = document.querySelector('img') | ||
|
@@ -16,9 +16,12 @@ function showText(text) { | |
paragraph.textContent = text | ||
} | ||
|
||
function recognizeImageText(file) { | ||
async function recognizeImageText(file) { | ||
showText('Recognizing the image text...') | ||
Tesseract.recognize(file).then((result) => showText(result.text)) | ||
const worker = await createWorker('eng') | ||
const fileRecognition = await worker.recognize(file) | ||
showText(fileRecognition.data.text) | ||
worker.terminate() | ||
} | ||
|
||
inputFile.addEventListener('change', (event) => { | ||
|