-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimage_request_IIIF.py
35 lines (23 loc) · 1.11 KB
/
image_request_IIIF.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
import requests
import os
import imageio
def download_images(manifest_url, output_folder):
response = requests.get(manifest_url)
manifest_data = response.json()
canvases = manifest_data['sequences'][0]['canvases']
# Controlla se la cartella di output esiste, altrimenti creala
if not os.path.exists(output_folder):
os.makedirs(output_folder)
for idx, canvas in enumerate(canvases):
image_url = canvas['images'][0]['resource']['@id']
image_filename = f"{idx+1}.jpg"
image_path = os.path.join(output_folder, image_filename)
image_response = requests.get(image_url)
with open(image_path, 'wb') as image_file:
image_file.write(image_response.content)
print(f"Download completato: {image_filename}")
image = imageio.imread(image_path)
manifest_url = "https://historica.unibo.it/json/iiif/20.500.14008/78706/267587/manifest"
output_folder = "C:/Users/erica/Documenti/immaginiAldrovandi"
# Chiamata alla funzione per scaricare le immagini
download_images(manifest_url, output_folder)