-
Notifications
You must be signed in to change notification settings - Fork 0
/
image_parser.py
30 lines (24 loc) · 1013 Bytes
/
image_parser.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
#########################################################
# This class is responsible for parsing the image file #
# using PIL we get data of all the pixels in the image #
#########################################################
from PIL import Image
class ImageParser:
def __init__(self, file_name):
self.__im = None
self.__open(file_name)
def __open(self, file_name):
try:
self.__im = Image.open(file_name).convert("RGB")
print("Image opened successfully...")
except IOError:
print("ERROR: Could not open image.")
print("Exiting with error code 1...")
exit(1)
def parse_image(self):
return list(self.__im.getdata(0)), self.__im.size
def print_info(self):
print("\n========== Image information ==========")
print(" The size of the image is " + str(self.__im.size))
print(" Image mode: ", self.__im.mode)
print("=======================================")