index.html
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 |
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Image to Text Program</title> <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet"> </head> <body class="bg-gray-100"> <div class="container mx-auto p-4"> <h1 class="text-2xl font-bold mb-4">Image to Text Program</h1> <input type="file" id="imageInput" accept="image/*" class="mb-4"> <button id="extractButton" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded"> Extract Text </button> <textarea id="outputTextarea" class="w-full h-40 mt-4 p-2 bg-white border border-gray-300 rounded"></textarea> <button id="copyButton" class="bg-green-500 hover:bg-green-700 text-white font-bold py-2 px-4 rounded mt-4"> Copy to Clipboard </button> </div> <script src='https://cdn.jsdelivr.net/npm/tesseract.js@5/dist/tesseract.min.js'></script> <script> const imageInput = document.getElementById('imageInput'); const extractButton = document.getElementById('extractButton'); const outputTextarea = document.getElementById('outputTextarea'); const copyButton = document.getElementById('copyButton'); extractButton.addEventListener('click', () => { const file = imageInput.files[0]; if (file) { const reader = new FileReader(); reader.onload = () => { const img = new Image(); img.src = reader.result; img.onload = () => { Tesseract.recognize(img) .then(({ data: { text } }) => { outputTextarea.value = text; }) .catch((error) => { console.error('Error:', error); }); }; }; reader.readAsDataURL(file); } }); copyButton.addEventListener('click', () => { outputTextarea.select(); document.execCommand('copy'); alert('Text copied to clipboard!'); }); </script> </body> </html> |