-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_strange.py
executable file
·153 lines (127 loc) · 5.06 KB
/
test_strange.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/env python3
import datetime
from JpegIPTC import JpegIPTC
if __name__ == '__main__': # pragma: no cover
# fetch iptc data from jpeg => iptc data present
# create a new jpeg file and add previous iptc data
print("")
print("TEST 1")
source = "76bde3fc961f0fa8733756922d1e2ed06311d804ec38b89dc60d6ba36d30e046.jpg"
source = "strange.jpg"
destination = "P1000056.jpg"
outputfile = "test.jpg"
with open(source, "rb") as file:
buffer = file.read()
with open(destination, "rb") as file:
results = file.read()
iptc_start = datetime.datetime.now()
jpegiptc_object = JpegIPTC()
jpegiptc_object.load_from_binarydata(buffer)
jpegiptc_object_d = JpegIPTC()
jpegiptc_object_d.load_from_binarydata(results)
#print("Copy IPTC data from "+source+" to "+destination)
#print(jpegiptc_object.get_raw_iptc())
jpegiptc_object_d.set_raw_iptc(jpegiptc_object.get_raw_iptc())
#print("Dumping raw data from new image")
newresults = jpegiptc_object_d.dump()
iptc_total_time = ( datetime.datetime.now() - iptc_start).total_seconds() * 1000
print(iptc_total_time)
if newresults is not None:
results = newresults
print("Dump OK : writing output to "+outputfile)
with open(outputfile, "wb") as binary_file:
binary_file.write(results)
binary_file.close()
del jpegiptc_object
del jpegiptc_object_d
# fetch iptc data from png file => no iptc data
# create a new jpeg file and add previous iptc data
print("")
print("TEST 2")
source="iptc-logo.png"
destination = "P1000056.jpg"
outputfile = "test2.jpg"
with open(destination, "rb") as file:
results = file.read()
iptc_start = datetime.datetime.now()
jpegiptc_object = JpegIPTC()
jpegiptc_object.load_from_file(source)
jpegiptc_object_d = JpegIPTC()
jpegiptc_object_d.load_from_binarydata(results)
#print(jpegiptc_object.get_raw_iptc())
jpegiptc_object_d.set_raw_iptc(jpegiptc_object.get_raw_iptc())
newresults = jpegiptc_object_d.dump()
iptc_total_time = ( datetime.datetime.now() - iptc_start).total_seconds() * 1000
print(iptc_total_time)
if newresults is not None:
results = newresults
print("Dump OK : writing output to "+outputfile)
with open(outputfile, "wb") as binary_file:
binary_file.write(results)
binary_file.close()
del jpegiptc_object
del jpegiptc_object_d
# fetch iptc data from jpeg => iptc data present
# create a new png file and add previous iptc data
# we don't support png file as output file
# so jpegiptc_object_d.dump should return None
# and you should not overwrite your initial result
print("")
print("TEST 3")
source = "76bde3fc961f0fa8733756922d1e2ed06311d804ec38b89dc60d6ba36d30e046.jpg"
destination = "iptc-logo.png"
outputfile = "test3.png"
with open(source, "rb") as file:
buffer = file.read()
with open(destination, "rb") as file:
results = file.read()
iptc_start = datetime.datetime.now()
jpegiptc_object = JpegIPTC()
jpegiptc_object.load_from_binarydata(buffer)
jpegiptc_object_d = JpegIPTC()
jpegiptc_object_d.load_from_binarydata(results)
#print("Copy IPTC data from "+source+" to "+destination)
#print(jpegiptc_object.get_raw_iptc())
jpegiptc_object_d.set_raw_iptc(jpegiptc_object.get_raw_iptc())
#print("Dumping raw data from new image")
newresults = jpegiptc_object_d.dump()
iptc_total_time = ( datetime.datetime.now() - iptc_start).total_seconds() * 1000
print(iptc_total_time)
if newresults is not None:
results = newresults
else:
print("Warning: newresults is None")
print("Dump OK : writing output to "+outputfile)
with open(outputfile, "wb") as binary_file:
binary_file.write(results)
binary_file.close()
del jpegiptc_object
del jpegiptc_object_d
# fetch iptc data from jpeg => iptc data present
# create a new png file and add previous iptc data
# we don't support png file as output file
# test save_as method
print("")
print("TEST 4")
source = "76bde3fc961f0fa8733756922d1e2ed06311d804ec38b89dc60d6ba36d30e046.jpg"
destination = "iptc-logo.png"
outputfile = "test4.png"
with open(source, "rb") as file:
buffer = file.read()
with open(destination, "rb") as file:
results = file.read()
iptc_start = datetime.datetime.now()
jpegiptc_object = JpegIPTC()
jpegiptc_object.load_from_binarydata(buffer)
jpegiptc_object_d = JpegIPTC()
jpegiptc_object_d.load_from_binarydata(results)
#print("Copy IPTC data from "+source+" to "+destination)
#print(jpegiptc_object.get_raw_iptc())
jpegiptc_object_d.set_raw_iptc(jpegiptc_object.get_raw_iptc())
#print("Dumping raw data from new image")
print("Dump OK : writing output to "+outputfile)
newresults = jpegiptc_object_d.save_as(outputfile)
iptc_total_time = ( datetime.datetime.now() - iptc_start).total_seconds() * 1000
print(iptc_total_time)
del jpegiptc_object
del jpegiptc_object_d