Get fractal coordinates from query string, call mandelbrot to generate image.

    Returns:
        The image, wrapped in an HTML response.

def handle_fractal():
    """Get fractal coordinates from query string, call mandelbrot to generate image.

    Returns:
        The image, wrapped in an HTML response.
    """

    if check_etag():
        return flask.make_response(), 304

    level = int(flask.request.args.get("l", "0"))
    x = float(int(flask.request.args.get("x", "0")))
    y = float(int(flask.request.args.get("y", "0")))

    if level < 0:
        level = 0

    grid_size = math.pow(2, level)

    x0 = "%.30g" % ((x - 0) / grid_size)
    y0 = "%.30g" % ((y - 0) / grid_size)
    x1 = "%.30g" % ((x + 1) / grid_size)
    y1 = "%.30g" % ((y + 1) / grid_size)

    print "Tile: %s %s %s %s" % (x0, y0, x1, y1)

    width = str(CONF['width'])
    height = str(CONF['height'])
    iters = str(CONF['iters'])

    cmd = ['./mandelbrot', width, height, iters, x0, y0, x1, y1]
    image_data = subprocess.check_output(cmd)

    response = flask.make_response(image_data)
    response.headers["Content-Type"] = "image/png"
    response.headers["cache-control"] = "public, max-age=600"
    response.headers["ETag"] = ETAG

    return response