-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdimensions.py
45 lines (38 loc) · 1.23 KB
/
dimensions.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
# file: dimensions.py
# save dimensions of images in a directory to a csv file
import csv
import subprocess
from pathlib import Path
def main(
directory: "path to image directory", # type: ignore
):
with open("_outputs/exhibits+thumbnails/_dimensions.csv", "w") as csv_fp:
csv_writer = csv.DictWriter(
csv_fp,
fieldnames=["filename", "width", "height"],
)
csv_writer.writeheader()
for p in Path(directory).iterdir():
if p.suffix == ".gif" or p.suffix == ".jpg" or p.suffix == ".png":
print(p)
result = subprocess.run(
[
"identify",
"-format",
"%w,%h",
p,
],
capture_output=True,
text=True,
)
width, height = result.stdout.split(",")
csv_writer.writerow(
{
"filename": p.name,
"width": width,
"height": height,
}
)
if __name__ == "__main__":
# fmt: off
import plac; plac.call(main)