-
-
Save PolCPP/9f4387093d510e57274dd7c083b77d62 to your computer and use it in GitHub Desktop.
#!/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()' |
@jbhanks I don't remember having to add that. But i'm using OSD 4.0.1
Here it is a production edz file and the code i'm actually using on production (well i turned it into a cli lib, the one in production is called from Laravel). https://ion.red/edz.zip as long as an example i ran with some random anime image.
You'll need vips installed, zip and php..
and to run it
php edzgen.php test.jpg ./ cont 1234
As for a working production example url how i can DM you one?
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 tried jpeg
, edz
and zip
.
Is php only needed for the generation script you included in the zip, or is it needed for the actual viewing?
It seems like it's failing the check of whether the file is an image (line 1543 in
tiledimage.js
) :