Ejemplo n.º 1
0
def interestingize(animal="cow"):
    if animal not in ANIMALS:
        abort(404)
    if request.method == "POST":
        image_raw = request.files.get("image")
        if image_raw is None:
            return "Must provide image in form field 'image'", 500

        try:
            image = Image.open(image_raw)
        except IOError:
            return "Could not decode image", 500

    else:
        url = request.values.get("src", None)
        if url is None:
            return redirect(url_for("index"))

        r = requests.get(url)
        if r.status_code != requests.codes.ok:
            r.raise_for_status()

        try:
            image = Image.open(StringIO(r.content))
        except IOError:
            return "Could not decode image", 500

    item = random.choice(items[animal]).copy()
    try:
        better_image = interestingizer.interestingize(image, item)
    except Exception, e:
        print "Could not run interestingize algorithm: %s" % e
        return "Could not interestingize", 500
Ejemplo n.º 2
0
def interestingize():
    image_raw = request.files.get("image")
    if image_raw:
        try:
            image = Image.open(image_raw)
        except IOError:
            return "Could not decode image", 500

        item = random.choice(items).copy()
        try:
            better_image = interestingizer.interestingize(image, item)
        except Exception, e:
            print "Could not run interestingize algorithm: %s" % e
            return "Could not interestingize", 500

        key = cache_image(better_image)
        return redirect(url_for('cache', key=key))