Skip to content

Commit

Permalink
feat: update file reader example
Browse files Browse the repository at this point in the history
  • Loading branch information
edysegura committed Jun 6, 2024
1 parent 053797d commit 049f2d2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
3 changes: 1 addition & 2 deletions file-reader/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand All @@ -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>
9 changes: 6 additions & 3 deletions file-reader/js/index.js
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')
Expand All @@ -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) => {
Expand Down

0 comments on commit 049f2d2

Please sign in to comment.