Created
May 22, 2020 01:45
-
-
Save PolCPP/9f4387093d510e57274dd7c083b77d62 to your computer and use it in GitHub Desktop.
Quick&Dirty script to transform DZI to EDZ. Should only need py2 bash & command line zip. To run just: python dzi2edz.py duomo duomo/duomo.dzi where duomo is your dzi folder and duomo/duomo.dzi is the xml file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
import json | |
import os | |
from zipfile import ZipFile | |
from xml.dom import minidom | |
dir_name = sys.argv[1] | |
fileHeader = 59 + len(dir_name) | |
zip_file = dir_name + ".zip" | |
dzi_file = minidom.parse(sys.argv[2]) | |
image_tag = dzi_file.getElementsByTagName('Image')[0] | |
size_tag = dzi_file.getElementsByTagName('Size')[0] | |
file_table = { | |
"Image": { | |
"TileFormat": "edz", | |
"Format": image_tag.attributes['Format'].value, | |
"Overlap": image_tag.attributes['Overlap'].value, | |
"TileSize": image_tag.attributes['TileSize'].value, | |
"Size": { | |
"Height": size_tag.attributes['Height'].value, | |
"Width": size_tag.attributes['Width'].value | |
}, | |
"ZipFile": zip_file, | |
"Ranges": {} | |
} | |
} | |
os.system("zip -Z store -r %s %s" % (zip_file, dir_name)) | |
f = open(zip_file, "r") | |
file_contents = f.read() | |
f.close() | |
with ZipFile(zip_file, 'r') as zip: | |
files = zip.infolist() | |
for file in files: | |
if not file.filename.endswith('/'): | |
#Slow safe way | |
#data = zip.read(file) | |
#offset = file_contents.find(data) | |
#size = len(data) | |
#Fast/Magic i don't get how i made it work way | |
offset = file.header_offset + fileHeader + len(file.filename.replace(dir_name + "/", "")); | |
size = file.file_size; | |
file_table["Image"]["Ranges"][file.filename] = { | |
"offset": offset, | |
"size": size | |
} | |
f = open(dir_name + ".json", "w") | |
f.write(json.dumps(file_table)) | |
f.close() | |
# 6285 | |
# 6350 | |
#python -c 'f=open("duomo.zip","rb");f.seek(6315);print(f.read(196));f.close()' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ok, with your demo zip I get the same result
Unable to open [object Object]: Unable to load TileSource
. I just followed you, so you should be able to DM me now. Thank you so much for your help!2 other questions:
What do you put for the
tileFormat
? I have triedjpeg
,edz
andzip
.Is php only needed for the generation script you included in the zip, or is it needed for the actual viewing?