Ejemplo n.º 1
0
def _image_data(bin_id, target, mimetype):
    b = get_object_or_404(Bin, pid=bin_id)
    try:
        arr = b.image(target)
    except KeyError:
        raise Http404("image data not found")
    image_data = format_image(arr, mimetype)
    return HttpResponse(image_data, content_type=mimetype)
Ejemplo n.º 2
0
def embed_image(image):
    """
    Converts an IFCB formatted image array into a base64 encoded string that can be shown as an embedded
    image in HTML
    """
    image_data = format_image(image).getvalue()

    return base64.b64encode(image_data).decode('ascii')
Ejemplo n.º 3
0
 def add_image(self, bin, image_number):
     """add one image to the database"""
     # collect values
     time = bin.pid.timestamp
     s = bin.schema
     target = bin[image_number]
     x = target[s.ROI_X]
     y = target[s.ROI_Y]
     xsiz = target[s.ROI_WIDTH]
     ysiz = target[s.ROI_HEIGHT]
     # convert image to ppm
     image_array = bin.images[image_number]
     image_ppm = format_image(image_array,
                              'image/x-portable-pixmap').getvalue()
     # write to database
     self._insert_row(bin.lid, image_number, time, x, y, xsiz, ysiz,
                      image_ppm)
Ejemplo n.º 4
0
def mosaic_page_image(request, bin_id):
    arr = _mosaic_page_image(request, bin_id)
    image_data = format_image(arr, 'image/png')

    return HttpResponse(image_data, content_type='image/png')