-
-
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()' |
Some progress: I just cloned this whole repo and got past the above errors, so I guess there must have been breaking changes since the OSD version this was based off of. It wasn't finding the tiles and I saw the paths were wrong, so I corrected the paths in the json file to remove the paths from my computer and just have the paths relative to the json file.
Now I am getting errors like Tile 10/1_1 failed to load: http://127.0.0.1:5002/static/dzi/onion_tonecurves_files.zip - error: Image load aborted
.
It seems like it's failing the check of whether the file is an image (line 1543 in tiledimage.js
) :
function onTileLoad( tiledImage, tile, time, image, errorMsg, tileRequest ) {
if ( !image ) {
$.console.log( "Tile %s failed to load: %s - error: %s", tile, tile.url, errorMsg );
/**
* Triggered when a tile fails to load.
*
* @event tile-load-failed
* @memberof OpenSeadragon.Viewer
* @type {object}
* @property {OpenSeadragon.Tile} tile - The tile that failed to load.
* @property {OpenSeadragon.TiledImage} tiledImage - The tiled image the tile belongs to.
* @property {number} time - The time in milliseconds when the tile load began.
* @property {string} message - The error message.
* @property {XMLHttpRequest} tileRequest - The XMLHttpRequest used to load the tile if available.
*/
tiledImage.viewer.raiseEvent("tile-load-failed", {
tile: tile,
tiledImage: tiledImage,
time: time,
message: errorMsg,
tileRequest: tileRequest
});
tile.loading = false;
tile.exists = false;
return;
}
@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?
When I first tried to run this, I got a decoding error, but I was able to run it after changing line 33 to
f = open(zip_file, "rb")
. However Although the json and zip files are created, I am unable to load the edz ("Unable to load TileSource").The js console gives me this:
Should I be pointing to the json file in lieu of the dzi file?
This is how I have done it:
The first one gives the TileSource error, the rest (including the original dzi) load fine.