def get_camera_image(camera_name):
        """
        Return a camera image in PNG format. URL parameters available:
        raw, scale=[float], min_value=[float], max_value[float], colormap[string].
        Colormap: See http://matplotlib.org/examples/color/colormaps_reference.html
        :param camera_name: Name of the camera to grab the image from.
        :return: PNG image.
        """

        camera = instance_manager.config_manager.load_camera(camera_name)
        raw = 'raw' in request.params
        scale = float(
            request.params["scale"]) if "scale" in request.params else None
        min_value = float(request.params["min_value"]
                          ) if "min_value" in request.params else None
        max_value = float(request.params["max_value"]
                          ) if "max_value" in request.params else None
        colormap_name = request.params.get("colormap")

        # Retrieve a single image from the camera.
        image_raw_bytes = camera.get_image(raw=raw)

        image = get_png_from_image(image_raw_bytes, scale, min_value,
                                   max_value, colormap_name)

        response.set_header('Content-type', 'image/png')
        return image
    def get_background_image(background_name):
        """
        Return a background file in PNG format. URL parameters available:
        scale=[float], min_value=[float], max_value[float], colormap[string].
        Colormap: See http://matplotlib.org/examples/color/colormaps_reference.html
        :param background_name: Background file name.
        :return: PNG image.
        """

        scale = float(request.params["scale"]) if "scale" in request.params else None
        min_value = float(request.params["min_value"]) if "min_value" in request.params else None
        max_value = float(request.params["max_value"]) if "max_value" in request.params else None
        colormap_name = request.params.get("colormap")

        image_raw_bytes = instance_manager.background_manager.get_background(background_name)

        image = get_png_from_image(image_raw_bytes, scale, min_value, max_value, colormap_name)

        response.set_header('Content-type', 'image/png')
        return image
    def test_camera_image(self):

        camera = self.instance_manager.config_manager.load_camera(
            self.simulation_camera)

        # Retrieve a single image from the camera.
        camera.connect()
        image_raw_bytes = camera.get_image()
        camera.disconnect()

        image = get_png_from_image(image_raw_bytes)

        self.assertEqual("png", imghdr.test_png(image, None),
                         "Image is not a valid PNG.")

        camera_size = camera.get_geometry()
        png_size = Image.open(BytesIO(image)).size

        self.assertEqual(camera_size, png_size,
                         "Camera and image size are not the same.")