screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/tesseract.js/2.1.4/tesseract.min.js"></script> </head> <body> <div id="app"> <h1>Vue Extract Text from Image</h1> <div class="upload-btn-wrapper"> <button class="btn">Upload Image</button> <input type="file" @change="loadImage" accept="image/*"> </div> <div v-if="image"> <img :src="image"> <button class="btn" @click="extractText">Extract Text</button> </div> <div v-if="loading"> <h2>Loading...<span class="loader"></span></h2> </div> <div v-if="extractedText"> <h2>Extracted Text</h2> <pre>{{ extractedText }}</pre> </div> </div> <script> new Vue({ el: '#app', data() { return { image: null, extractedText: null, loading: false, }; }, methods: { loadImage(event) { const file = event.target.files[0]; const reader = new FileReader(); reader.readAsDataURL(file); reader.onload = () => { this.image = reader.result; }; }, extractText() { this.loading = true; Tesseract.recognize( this.image, 'eng+hin', { logger: m => console.log(m) } ).then(({ data: { text } }) => { this.extractedText = text; }).finally(() => { this.loading = false; }); }, }, }); </script> <style scoped> #app { max-width: 600px; margin: 0 auto; padding: 20px; text-align: center; font-family: 'Montserrat', sans-serif; } h1 { font-size: 40px; margin-bottom: 30px; color: #444; } .upload-btn-wrapper { position: relative; overflow: hidden; display: inline-block; margin: 20px auto; } .btn { font-size: 18px; font-weight: bold; color: #fff; background-color: #007bff; padding: 10px 20px; border-radius: 4px; cursor: pointer; border: none; } .btn:hover { background-color: #0062cc; } .upload-btn-wrapper input[type=file] { font-size: 100px; position: absolute; left: 0; top: 0; opacity: 0; } img { max-width: 100%; margin-top: 20px; border: 1px solid #ccc; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); } .loader { border: 4px solid #f3f3f3; border-top: 4px solid #3498db; border-radius: 50%; width: 20px; height: 20px; animation: spin 2s linear infinite; display: inline-block; margin: 0 10px; } @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } } h2 { font-size: 28px; margin-top: 50px; color: #444; } pre { font-size: 18px; text-align: left; white-space: pre-wrap; word-wrap: break-word; background-color: #f8f9fa; border: 1px solid #ccc; padding: 20px; margin-top: 20px; } </style> </body> </html>