Example #1
0
def tile(path, level, col, row, format):
    slide = _get_slide(dz.config['slides_dir'], path)
    format = format.lower()
    if format != 'jpeg' and format != 'png':
        abort(404)
    try:
        tile = slide.get_tile(level, (col, row))
    except ValueError:
        abort(404)
    buf = PILBytesIO()

    tile.save(buf, 'jpeg', quality=90)
    resp = make_response(buf.getvalue())
    resp.mimetype = 'image/%s' % format
    return resp
def tile(path, level, col, row, format):
    slide = _get_slide(dz.config['slides_dir'], path)
    format = format.lower()
    if format != 'jpeg' and format != 'png':
        abort(404)
    try:
        tile = slide.get_tile(level, (col, row))
    except ValueError:
        abort(404)
    buf = PILBytesIO()
 
    tile.save(buf, 'jpeg', quality=90)
    resp = make_response(buf.getvalue())
    resp.mimetype = 'image/%s' % format
    return resp
Example #3
0
    def get(self, id, level, x, y):
        """
        Get slide tile
        ---
        tags:
          - Tile
        parameters:
          - in: path
            name: id
            description: MonogDB ObjectId appended to it the level -- Example 57bf3c092f9b2e1595b29730
            type: string
          - in: path
            name: level
            description: The zoom level
            type: integer
          - in: path
            name: x
            description: The column
            type: integer
          - in: path
            name: y
            description: The row
            type: integer
        responses:
          200:
            description: Returns the slide information
          404:
          	description: Invalid slide Id or slide not found
        """

        if not ObjectId.is_valid(id):
            resp = {"status": 404, "message": "Invalid slide Id " + id}
            return Response(dumps(resp),
                            status=404,
                            mimetype='application/json')

        image = self.slides.find_one({'_id': ObjectId(id)})
        path = image["path"]
        slide = get_slide(path)

        try:
            tile = slide.get_tile(level, (x, y))
            buf = PILBytesIO()
            tile.save(buf, 'jpeg', quality=90)
            return Response(buf.getvalue(), status=200, mimetype='image/jpeg')
        except ValueError:
            Response(None, status=404)
Example #4
0
    def get(self, id):
        """
        Get slide label image
        ---
        tags:
          - Label Image
        parameters:
          - in: path
            name: id
            description: MonogDB ObjectId -- Example 57bf3c092f9b2e1595b29730
            type: string
          - in: query
            name: username
            description: Username to access the resource
            type: string
          - in: query
            name: password
            description: Password to access the resource
            type: string
        responses:
          200:
            description: Returns the slide label image
          404:
          	description: Invalid slide Id or label image not found
        """

        image = self.slides.find_one({'_id': ObjectId(id)})
        path = image["path"]
        osr = OpenSlide(path)
        dim = (int(self.config["macro_width"]),
               int(self.config["macro_height"]))

        if "label" in osr.associated_images.keys():
            im = osr.associated_images["label"]
            im.thumbnail(dim)
            buf = PILBytesIO()
            im.save(buf, "jpeg", quality=90)
            return Response(buf.getvalue(), status=200, mimetype='image/jpeg')
        else:
            resp = {
                "status": 404,
                "message": "Label image not found this resource"
            }
            return Response(dumps(resp),
                            status=404,
                            mimetype='application/json')
Example #5
0
	def get(self, id, level, x, y):
		"""
        Get slide tile
        ---
        tags:
          - Tile
        parameters:
          - in: path
            name: id
            description: MonogDB ObjectId appended to it the level -- Example 57bf3c092f9b2e1595b29730
            type: string
          - in: path
            name: level
            description: The zoom level
            type: integer
          - in: path
            name: x
            description: The column
            type: integer
          - in: path
            name: y
            description: The row
            type: integer
        responses:
          200:
            description: Returns the slide information
          404:
          	description: Invalid slide Id or slide not found
        """

		if not ObjectId.is_valid(id):
			resp = {"status": 404, "message": "Invalid slide Id " + id}
			return Response(dumps(resp), status=404, mimetype='application/json')

		image = self.slides.find_one({'_id': ObjectId(id)})
		path = image["path"]
		slide = get_slide(path)
		
		try:
			tile = slide.get_tile(level, (x, y))
			buf = PILBytesIO()
			tile.save(buf, 'jpeg', quality=90)
			return Response(buf.getvalue(), status=200, mimetype='image/jpeg')
		except ValueError:
			Response(None, status=404)
Example #6
0
	def get(self, id):
		"""
        Get slide label image
        ---
        tags:
          - Label Image
        parameters:
          - in: path
            name: id
            description: MonogDB ObjectId -- Example 57bf3c092f9b2e1595b29730
            type: string
          - in: query
            name: username
            description: Username to access the resource
            type: string
          - in: query
            name: password
            description: Password to access the resource
            type: string
        responses:
          200:
            description: Returns the slide label image
          404:
          	description: Invalid slide Id or label image not found
        """

		image = self.slides.find_one({'_id': ObjectId(id)})
		path = image["path"]
		osr = OpenSlide(path)
		dim = (int(self.config["macro_width"]), int(self.config["macro_height"]))

		if "label" in osr.associated_images.keys():
			im = osr.associated_images["label"]
			im.thumbnail(dim)
			buf = PILBytesIO()
			im.save(buf, "jpeg", quality=90)
			return Response(buf.getvalue(), status=200, mimetype='image/jpeg')
		else:
			resp = {"status": 404, "message": "Label image not found this resource"}
			return Response(dumps(resp), status=404, mimetype='application/json')
Example #7
0
def getThumbnail(path):
    """This will return the 0/0 tile later whch in the case of an SVS image is actually the thumbnail..... """

    path = os.path.abspath(os.path.join(dz.config['slides_dir'], path))
    osr = OpenSlide(path)
    format = 'jpeg'

    format = format.lower()
    if format != 'jpeg' and format != 'png':
        # Not supported by Deep Zoom
        abort(404)
    try:
        thumb = osr.get_thumbnail((300, 300))
    except ValueError:
        # Invalid level or coordinates
        abort(404)

    buf = PILBytesIO()
    thumb.save(buf, 'jpeg', quality=90)
    resp = make_response(buf.getvalue())
    resp.mimetype = 'image/%s' % format
    return resp
def getThumbnail(path):
    """This will return the 0/0 tile later whch in the case of an SVS image is actually the thumbnail..... """

    path = os.path.abspath(os.path.join(dz.config['slides_dir'], path))
    osr = OpenSlide(path)
    format = 'jpeg'

    format = format.lower()
    if format != 'jpeg' and format != 'png':
        # Not supported by Deep Zoom
        abort(404)
    try:
        thumb = osr.get_thumbnail( (300,300))
    except ValueError:
        # Invalid level or coordinates
        abort(404)

    buf = PILBytesIO()
    thumb.save(buf, 'jpeg', quality=90)
    resp = make_response(buf.getvalue())
    resp.mimetype = 'image/%s' % format
    return resp