summaryrefslogtreecommitdiff
path: root/scrape-codex.py
diff options
context:
space:
mode:
Diffstat (limited to 'scrape-codex.py')
-rw-r--r--scrape-codex.py22
1 files changed, 14 insertions, 8 deletions
diff --git a/scrape-codex.py b/scrape-codex.py
index 6e3cb55..ffec8f7 100644
--- a/scrape-codex.py
+++ b/scrape-codex.py
@@ -51,6 +51,14 @@ def parallel_fetch(dataset):
with Pool(processes=agents) as pool:
pool.starmap(fetch_file, dataset, chunksize)
+def load_image(fn):
+ try:
+ image = Image.open(fn)
+ width, height = image.size
+ return image, width, height
+ except:
+ return None, 0, 0
+
# Fetch all the tiles from a tile server and then compose them into a single image
def grab(s, n):
page = "{:03d}{}".format(n, s)
@@ -73,14 +81,12 @@ def grab(s, n):
hh = 258 * (TILE_H - 1)
fn = "./{}/{}/{}/{}_{}.jpg".format(TAG, ZOOM, page, 0, 0)
- image = Image.open(fn)
- width, height = image.size
+ image, width, height = load_image(fn)
ww += width
hh += height
fn = "./{}/{}/{}/{}_{}.jpg".format(TAG, ZOOM, page, TILE_W, TILE_H)
- image = Image.open(fn)
- width, height = image.size
+ image, width, height = load_image(fn)
ww += width
hh += height
@@ -91,10 +97,10 @@ def grab(s, n):
y = 0
for j in range(0, TILE_H + 1):
fn = "./{}/{}/{}/{}_{}.jpg".format(TAG, ZOOM, page, i, j)
- image = Image.open(fn)
- width, height = image.size
- canvas.paste(image, (x, y))
- y += height
+ image, width, height = load_image(fn)
+ if image:
+ canvas.paste(image, (x, y))
+ y += height
x += width
canvas.save("./{}/{}/{}_{}.jpg".format(TAG, ZOOM, page, ZOOM))