Openlayers / Deepzoom format
Jan Harkes
jaharkes at cs.cmu.edu
Wed Oct 3 16:15:53 EDT 2012
On Wed, Oct 03, 2012 at 03:50:12PM -0400, Jan Harkes wrote:
> On Wed, Oct 03, 2012 at 07:22:46AM +0200, PD Dr. M. Weihrauch wrote:
> > only supports tiles of 256x256 and deepzoom may have different
> > tile-sizes on the right border and the bottom border of the images.
>
> I just looked at the openslide-python:openslide/deepzoom.py code and it
> looks like it will always return square (256x256) tiles.
And after looking a second time, it actually does clip the tiles at the
edge. It does already handle compositing the image data returned by
openslide onto a tile that is filled with the background color, so
changing the code to return fixed size tiles is (probably) fairly easy.
Openseadragon probably wouldn't like it though so I don't see a trivial
fix that would work well for all cases here.
So the dynamic tile server would have to use something like the following
(completely untested) code to support map viewers,
Jan
from PIL import Image
@app.route('/<slug>_osm/<int:level>/<int:col>_<int:row>.<format>')
def osm_tile(slug, level, col, row, format):
### mapviewers expect to see 256x256 tiles at level 0
level = level + 8
format = format.lower()
if format != 'jpeg' and format != 'png':
# Not supported by Deep Zoom
abort(404)
try:
tile = app.slides[slug].get_tile(level, (col, row))
except KeyError:
# Unknown slug
abort(404)
except ValueError:
# Invalid level or coordinates
abort(404)
### if the tile is clipped, paste it into a 256x256 tile.
if tile.size != (256,256):
full = Image.new('RGB', (256,256), '#000')
full.paste(tile, (0,0))
tile = full
buf = StringIO()
tile.save(buf, format, quality=app.config['DEEPZOOM_TILE_QUALITY'])
resp = make_response(buf.getvalue())
resp.mimetype = 'image/%s' % format
return resp
More information about the openslide-users
mailing list