-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprocess_image.py
57 lines (45 loc) · 1.5 KB
/
process_image.py
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
import io
import os
from PIL import Image
import binascii
import deframer
def process(in_file,characters_to_remove):
no_header = []
bad_words = ["1: [GEOSCAN]"]
with open(in_file) as dumpfile:
for line in dumpfile:
if not any(bad_word in line for bad_word in bad_words): #tnx stackoverflow =D
no_header.append(line)
f_lines = no_header
f_lines_joined = []
f_joined = ""
for i in range(len(f_lines)):
if f_lines[i] == "":
pass
else:
f_lines_joined.append(f_lines[i].replace(" ","")[characters_to_remove:len(f_lines[i].replace(" ",""))])
for i in range(len(f_lines_joined)):
f_joined = f_joined+f_lines_joined[i]
#f_joined = f_joined.replace("\n","").replace("\r","")
f_joined = f_joined.split("\n")
f_joined = list(filter(None, f_joined))
return f_joined
def process_RAW(f_joined,out_file):
o = open(out_file,'wb')
o.write(binascii.unhexlify(f_joined))
o.close()
print("Wrote raw JPEG!")
def process_image(f_joined,out_file):
print("Writing complete JPEG...")
image_data = bytearray.fromhex(f_joined)
image_geoscan = Image.open(io.BytesIO(image_data))
image_geoscan.save(out_file)
print("Done!")
def process_multiple(f_joined,outfile):
deframer.deframe(f_joined,outfile)
def check_valid(filename):
try:
Image.open(filename)
return True
except:
return False