Example #1
0
def upload():
    """Handle a new file upload."""
    if request.method == 'GET':
        return jsonify(files=session['files'])
    elif request.method == 'POST' and 'file' in request.files:
        ip = request.environ['REMOTE_ADDR']
        name = uuid.uuid4().hex
        name += os.path.splitext(request.files['file'].filename)[1].lower()
        filename = photos.save(request.files['file'], folder=ip, name=name)
        path = photos.path(filename)
        gen_thumbnail(path, path + ".t.jpg")
        gen_histogram(path, path + ".h.png")
        photo = {"name": filename, "url": photos.url(filename)}
        session['files'].append(photo)
        session.modified = True
        return jsonify(photo)
    else:
        abort(400)
Example #2
0
def upload():
    """Handle a new file upload."""
    if request.method == 'GET':
        return jsonify(files=session['files'])
    elif request.method == 'POST' and 'file' in request.files:
        ip = request.environ['REMOTE_ADDR']
        name = uuid.uuid4().hex
        name += os.path.splitext(request.files['file'].filename)[1].lower()
        filename = photos.save(request.files['file'], folder=ip, name=name)
        path = photos.path(filename)
        gen_thumbnail(path, path+".t.jpg")
        gen_histogram(path, path+".h.png")
        photo = {"name": filename, "url": photos.url(filename)}
        session['files'].append(photo)
        session.modified = True
        return jsonify(photo)
    else:
        abort(400)
Example #3
0
def operate(func, filename):
    """
    Given an image editing function and filename, perform the operation,
    generate required histograms and thumbnails, then return the new
    image's URL.
    """
    path = photos.path(filename)
    if (os.path.exists(path)):
        ip = request.environ["REMOTE_ADDR"]
        remove_temp_files(ip, path)
        ext = os.path.splitext(path)[1]
        tmp = temp_file_path(request.environ["REMOTE_ADDR"], ext)
        func(path, tmp, request.form)
        gen_histogram(tmp, tmp + ".h.png")
        gen_thumbnail(tmp, tmp + ".t.jpg")
        return jsonify({'url': url_from_path(tmp)})
    else:
        abort(400)
Example #4
0
def operate(func, filename):
    """
    Given an image editing function and filename, perform the operation,
    generate required histograms and thumbnails, then return the new
    image's URL.
    """
    path = photos.path(filename)
    if(os.path.exists(path)):
        ip = request.environ["REMOTE_ADDR"]
        remove_temp_files(ip, path)
        ext = os.path.splitext(path)[1]
        tmp = temp_file_path(request.environ["REMOTE_ADDR"], ext)
        func(path, tmp, request.form)
        gen_histogram(tmp, tmp+".h.png")
        gen_thumbnail(tmp, tmp+".t.jpg")
        return jsonify({'url': url_from_path(tmp)})
    else:
        abort(400)