-
Notifications
You must be signed in to change notification settings - Fork 0
/
imgInfo.py
59 lines (43 loc) · 1.98 KB
/
imgInfo.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
58
59
import io
import os
from PIL import Image, ImageCms
class GetImgInfo():
def __init__(self, rgb_image):
self.rgb_image = Image.open(rgb_image)
self.get_icc_info()
self.rgb_image.close()
def get_icc_info(self):
icc = self.rgb_image.info.get('icc_profile')
if icc:
if type(icc) == tuple:
f = io.BytesIO(icc[0]) # esto es necesario para tiff porque el perfil aparece como tuple no str
else:
f = io.BytesIO(icc)
self.profile = ImageCms.ImageCmsProfile(f)
self.iccDescription = ImageCms.getProfileDescription(self.profile)
# self.iccInfo = ImageCms.getProfileInfo(self.profile) #copyright
# self.iccModel = ImageCms.getProfileModel(self.profile) #vacio
# print(self.iccDescription)
illum = str(self.profile.profile.media_white_point_temperature)
self.iccInfoDic = {
"fileName": self.profile.profile.profile_description,
"copyright": self.profile.profile.copyright,
# "fecha":self.profile.profile.creation_date, #he detectado algun error con el formato de algunas fechas, revisar!
"blanco": "D" + illum[0:2],
"pcs": self.profile.profile.xcolor_space,
"version": self.profile.profile.manufacturer,
"model": self.profile.profile.model,
"type": self.profile.profile.device_class # scnr son los input
}
else:
self.iccInfoDic = {
"fileName": "Warning no ICC Profile Found!",
"copyright": "", "fecha": "", "blanco": "?", "pcs": "", "version": "", "model": "", "type": ""
}
# print(self.iccInfoDic)
return self.iccInfoDic
def image_name(self):
return os.path.basename(self.rgb_image.filename)
# return(exif)
# a = getImgInfo("/Users/jpereira/Pictures/DSC_0205.tif")
# print(a.imageMetadata())