# HG changeset patch # User Tero Marttila # Date 1410725896 -10800 # Node ID a3bbecbd31e78ab4302dd46805e78281a88f8266 # Parent 8eff4a9fdd5ea9cd26bd27dfd281509660c046ad pngtile.tile: limit zoom; fix tile row/col mixup with just x/y diff -r 8eff4a9fdd5e -r a3bbecbd31e7 pngtile/tile.py --- a/pngtile/tile.py Sun Sep 14 23:17:45 2014 +0300 +++ b/pngtile/tile.py Sun Sep 14 23:18:16 2014 +0300 @@ -9,8 +9,10 @@ ## Coordinates # width of a tile -TILE_WIDTH = 256 -TILE_HEIGHT = 256 +TILE_SIZE = 256 + +# maximum zoom out +MAX_ZOOM = 4 # max. output resolution to allow MAX_PIXELS = 1920 * 1200 @@ -54,10 +56,13 @@ y = int(request.args['y']) zoom = int(request.args.get('zoom', "0")) - # safely limit + # safety limit if width * height > MAX_PIXELS: raise exceptions.BadRequest("Image size: %d * %d > %d" % (width, height, MAX_PIXELS)) + if zoom > MAX_ZOOM: + raise exceptions.BadRequest("Image zoom: %d > %d" % (zoom, MAX_ZOOM)) + x = scale(x, zoom) y = scale(y, zoom) @@ -72,14 +77,17 @@ Handle request for image tile """ - width = TILE_WIDTH - height = TILE_HEIGHT - row = int(request.args['row']) - col = int(request.args['col']) + width = TILE_SIZE + height = TILE_SIZE + x = int(request.args['x']) + y = int(request.args['y']) zoom = int(request.args.get('zoom', "0")) + + if zoom > MAX_ZOOM: + raise exceptions.BadRequest("Image zoom: %d > %d" % (zoom, MAX_ZOOM)) - x = scale(row * width, zoom) - y = scale(col * height, zoom) + x = scale(x * width, zoom) + y = scale(y * height, zoom) try: return image.tile_mem(width, height, x, y, zoom) @@ -100,7 +108,7 @@ if 'w' in request.args and 'h' in request.args and 'x' in request.args and 'y' in request.args: png = self.render_region(request, image) - elif 'row' in request.args and 'col' in request.args: + elif 'x' in request.args and 'y' in request.args: png = self.render_tile(request, image) else: