Esempio n. 1
0
def index():
    """Main view, the only view serving HTML"""

    old_gif = "static/images/test-radar2.gif"
    new_gif = "static/images/new-radar.gif"
    image = Image.open(old_gif)
    new_im = change_palette(image, nws_palette("rgb"), new_palette("rgb"))
    new_im.save(new_gif, "GIF", transparency=0)

    return render_template(
        "index.html", old_gif=old_gif, new_gif=new_gif, old_palette=nws_palette("rgb"), new_palette=new_palette("hsla")
    )
Esempio n. 2
0
def palette():
    """GET requests are returned a palette in JSON
       POST expects to receive a JSON palette, which is then
       used to generate a sample image with the palette and return
       a cache-busting path to the image."""

    if request.method == "GET":  # if initial request, GET
        # create palettes, images
        return json.dumps(
            {
                "nwsPalette": nws_palette("rgb"),
                "newPalette": new_palette("hsla"),
                "baseImageSrc": "static/images/test-radar2.gif",
                "newImageSrc": "static/images/new-radar.gif",
            }
        )
    elif request.method == "POST":
        data = request.get_json(force=True)
        hsla_palette = data
        rgb_palette = hsla_to_rgb(hsla_palette)
        image_src = make_sample_image(rgb_palette)
        new_image_src = "%s?%d" % (image_src, int(time.time()))
        return json.dumps({"newImageSrc": new_image_src})
    else:
        # TODO: return something better
        return "Shit!"
Esempio n. 3
0
def make_sample_image(palette):

    old_gif = 'static/images/test-radar2.gif'
    new_gif = 'static/images/new-radar.gif'
    image = Image.open(old_gif)
    new_im = change_palette(image, nws_palette('rgb'), palette)
    new_im.save(new_gif, "GIF", transparency=0)

    return new_gif