Silverbelt
commited on
Commit
•
fe301ed
1
Parent(s):
80960ec
bugfix script and jpg support
Browse files
scripts/generate-icat-comparison-projects.py
CHANGED
@@ -32,6 +32,42 @@ def get_png_dimensions(file_path):
|
|
32 |
|
33 |
return width, height
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
# Get the directory of the current script
|
36 |
script_dir = os.path.dirname(os.path.abspath(__file__))
|
37 |
|
@@ -65,49 +101,49 @@ for root, dirs, files in os.walk(base_dir):
|
|
65 |
# Add the file (with its full path) to the corresponding group
|
66 |
file_groups[number].append(os.path.join(root, file))
|
67 |
|
68 |
-
# JSON structure template
|
69 |
-
json_structure = {
|
70 |
-
"uiVisibility": {
|
71 |
-
"antiAliasSelect": True,
|
72 |
-
"fullscreenButton": True,
|
73 |
-
"gridSelect": True,
|
74 |
-
"helpButton": True,
|
75 |
-
"layersButton": True,
|
76 |
-
"layoutTabs": True,
|
77 |
-
"loopButton": True,
|
78 |
-
"mediaInfo": True,
|
79 |
-
"pixelDataButton": False,
|
80 |
-
"progressBar": True,
|
81 |
-
"setSelect": False,
|
82 |
-
"speedSelect": True,
|
83 |
-
"startEndTime": True,
|
84 |
-
"timeDisplay": True,
|
85 |
-
"titleBar": True,
|
86 |
-
"videoControls": True,
|
87 |
-
"zoomSelect": True,
|
88 |
-
"contentSidebar": True,
|
89 |
-
"timeline": True,
|
90 |
-
"controlBar": True,
|
91 |
-
"addFilterBtn": True,
|
92 |
-
"addLogoBtn": True,
|
93 |
-
"inOutSlider": True,
|
94 |
-
"timelineInOutSlider": False,
|
95 |
-
"appSettingsBtn": True
|
96 |
-
},
|
97 |
-
"sets": []
|
98 |
-
}
|
99 |
-
|
100 |
# Fill JSON structure with grouped files
|
101 |
for number, group in file_groups.items():
|
102 |
media_files = []
|
103 |
media_order = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
|
105 |
for file_path in group:
|
106 |
file_name = os.path.basename(file_path)
|
107 |
base_name = file_name.rsplit('.', 1)[0]
|
108 |
hex_id = uuid.uuid4().hex # Generate a unique hex ID for each file
|
109 |
cleaned_path = os.path.abspath(file_path).replace('\\', '%5C').replace(':', '%3A')
|
110 |
-
width, height =
|
111 |
|
112 |
# Example media entry
|
113 |
media_entry = {
|
|
|
32 |
|
33 |
return width, height
|
34 |
|
35 |
+
def get_jpeg_dimensions(file_path):
|
36 |
+
"""
|
37 |
+
Returns the (width, height) of a JPG image by reading the file's metadata.
|
38 |
+
"""
|
39 |
+
with open(file_path, 'rb') as f:
|
40 |
+
f.seek(0)
|
41 |
+
data = f.read(24)
|
42 |
+
|
43 |
+
# Check if file is JPEG
|
44 |
+
if data[0:2] == b'\xff\xd8': # JPEG files start with 0xFFD8
|
45 |
+
while True:
|
46 |
+
f.seek(2, 1) # Skip marker
|
47 |
+
marker = f.read(2)
|
48 |
+
if marker[0] == 0xFF and marker[1] == 0xC0: # Start of Frame marker
|
49 |
+
f.seek(3, 1) # Skip precision byte
|
50 |
+
height = int.from_bytes(f.read(2), 'big')
|
51 |
+
width = int.from_bytes(f.read(2), 'big')
|
52 |
+
return width, height
|
53 |
+
else:
|
54 |
+
size = int.from_bytes(f.read(2), 'big')
|
55 |
+
f.seek(size - 2, 1) # Skip to the next block
|
56 |
+
else:
|
57 |
+
raise ValueError("Not a JPEG file")
|
58 |
+
|
59 |
+
def get_image_dimensions(file_path):
|
60 |
+
extension = os.path.splitext(file_path)[-1].lower()
|
61 |
+
|
62 |
+
if extension == '.jpg' or extension == '.jpeg':
|
63 |
+
return get_jpeg_dimensions(file_path)
|
64 |
+
elif extension == '.png':
|
65 |
+
return get_png_dimensions(file_path)
|
66 |
+
else:
|
67 |
+
raise ValueError("Unsupported file format")
|
68 |
+
|
69 |
+
|
70 |
+
|
71 |
# Get the directory of the current script
|
72 |
script_dir = os.path.dirname(os.path.abspath(__file__))
|
73 |
|
|
|
101 |
# Add the file (with its full path) to the corresponding group
|
102 |
file_groups[number].append(os.path.join(root, file))
|
103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
# Fill JSON structure with grouped files
|
105 |
for number, group in file_groups.items():
|
106 |
media_files = []
|
107 |
media_order = []
|
108 |
+
|
109 |
+
# JSON structure template
|
110 |
+
json_structure = {
|
111 |
+
"uiVisibility": {
|
112 |
+
"antiAliasSelect": True,
|
113 |
+
"fullscreenButton": True,
|
114 |
+
"gridSelect": True,
|
115 |
+
"helpButton": True,
|
116 |
+
"layersButton": True,
|
117 |
+
"layoutTabs": True,
|
118 |
+
"loopButton": True,
|
119 |
+
"mediaInfo": True,
|
120 |
+
"pixelDataButton": False,
|
121 |
+
"progressBar": True,
|
122 |
+
"setSelect": False,
|
123 |
+
"speedSelect": True,
|
124 |
+
"startEndTime": True,
|
125 |
+
"timeDisplay": True,
|
126 |
+
"titleBar": True,
|
127 |
+
"videoControls": True,
|
128 |
+
"zoomSelect": True,
|
129 |
+
"contentSidebar": True,
|
130 |
+
"timeline": True,
|
131 |
+
"controlBar": True,
|
132 |
+
"addFilterBtn": True,
|
133 |
+
"addLogoBtn": True,
|
134 |
+
"inOutSlider": True,
|
135 |
+
"timelineInOutSlider": False,
|
136 |
+
"appSettingsBtn": True
|
137 |
+
},
|
138 |
+
"sets": []
|
139 |
+
}
|
140 |
|
141 |
for file_path in group:
|
142 |
file_name = os.path.basename(file_path)
|
143 |
base_name = file_name.rsplit('.', 1)[0]
|
144 |
hex_id = uuid.uuid4().hex # Generate a unique hex ID for each file
|
145 |
cleaned_path = os.path.abspath(file_path).replace('\\', '%5C').replace(':', '%3A')
|
146 |
+
width, height = get_image_dimensions(file_path)
|
147 |
|
148 |
# Example media entry
|
149 |
media_entry = {
|