-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathEmailScamDetector.js
54 lines (48 loc) · 1.5 KB
/
EmailScamDetector.js
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
import React, { useState } from 'react';
import { View, Text, TouchableOpacity, Image } from 'react-native';
import ImagePicker from 'react-native-image-picker';
import Tesseract from 'tesseract.js';
const EmailScamDetector = () => {
const [textFromImage, setTextFromImage] = useState('');
const pickImage = () => {
const options = {
title: 'Select Email Screenshot',
storageOptions: {
skipBackup: true,
path: 'images',
},
};
ImagePicker.showImagePicker(options, response => {
if (response.didCancel) {
console.log('User cancelled image picker');
} else if (response.error) {
console.log('ImagePicker Error: ', response.error);
} else {
const imageData = response.data;
const imageUri = `data:image/jpeg;base64,${imageData}`;
Tesseract.recognize(
imageUri,
'eng',
{ logger: info => console.log(info) }
).then(({ data: { text } }) => {
console.log('Extracted Text:', text);
setTextFromImage(text);
}).catch(error => console.error(error));
}
});
};
return (
<View>
<TouchableOpacity onPress={pickImage}>
<Text>Select Email Screenshot</Text>
</TouchableOpacity>
{textFromImage ? (
<View>
<Text>Extracted Text:</Text>
<Text>{textFromImage}</Text>
</View>
) : null}
</View>
);
};
export default EmailScamDetector;