Exemplo n.º 1
0
def post_meme():
    meme_id = dao.create_meme(get_db(), int(request.form['image']),
                              request.form['top'], request.form['bottom'])
    image_name = dao.get_image_path(get_db(), int(request.form['image']))
    memegenerator.gen_meme(image_name, request.form['top'],
                           request.form['bottom'], meme_id)
    return redirect(url_for('static', filename='memes/%d.png' % meme_id))
Exemplo n.º 2
0
def meme_image_path(meme_image, top, bottom, ext):
    file_path = derive_meme_path(meme_image, top, bottom, ext)
    app.logger.debug('Looking for file: "%s"', file_path)
    if os.path.exists(file_path):
        app.logger.info('Found meme in cache: "%s"', file_path)
    else:
        app.logger.info('Generating "%s"', file_path)
        meme_path = get_template_path(meme_image)
        gen_meme(meme_path + '.jpg', top, bottom, file_path)

    return file_path
Exemplo n.º 3
0
def meme_image_path(meme_image, top, bottom, ext):
    file_path = derive_meme_path(meme_image, top, bottom, ext)
    app.logger.debug('Looking for file: "%s"', file_path)
    try:
        open(file_path)
        app.logger.info('Found meme in cache: "%s"', file_path)
    except IOError:
        app.logger.info('Generating "%s"', file_path)
        meme_path = os.path.join(TEMPLATES_PATH, meme_image)
        gen_meme(meme_path + '.jpg', top, bottom, file_path)

    return file_path
Exemplo n.º 4
0
def meme_image_path(meme_image, top, bottom, ext):
    file_path = derive_meme_path(meme_image, top, bottom, ext)
    app.logger.debug('Looking for file: "%s"', file_path)
    try:
        open(file_path)
        app.logger.info('Found meme in cache: "%s"', file_path)
    except IOError:
        app.logger.info('Generating "%s"', file_path)
        meme_path = os.path.join(TEMPLATES_PATH, meme_image)
        gen_meme(meme_path + '.jpg', top, bottom, file_path)

    return file_path
Exemplo n.º 5
0
def post_meme():
    meme_id = dao.create_meme(get_db(),
                              int(request.form['image']),
                              request.form['top'],
                              request.form['bottom'])
    image_name = dao.get_image_path(get_db(),
                                    int(request.form['image']))
    memegenerator.gen_meme(image_name,
                           request.form['top'],
                           request.form['bottom'],
                           meme_id)
    return redirect(url_for('static', filename='memes/%d.png' % meme_id))
Exemplo n.º 6
0
def post_meme():
    template_id = request.form["template"]
    top = request.form["top"]
    bottom = request.form["bottom"]

    #TODO: create id is what None here is supposed to be
    meme_id = dao.create_meme(mongo.db, template_id, MemeText(top, bottom),
                              None)

    template_name = dao.get_template_filename(mongo.db, template_id)
    memegenerator.gen_meme(template_name, top, bottom, meme_id)

    return redirect(url_for("get_memes"))
Exemplo n.º 7
0
def post_meme():
    meme_id = dao.create_meme(get_db(), int(request.form['image']),
                              request.form['top'], request.form['bottom'])
    image_name = dao.get_image_path(get_db(), int(request.form['image']))
    memegenerator.gen_meme(image_name, request.form['top'],
                           request.form['bottom'], meme_id)
    image = dict()
    image['id'] = meme_id
    imagePath = url_for('static', filename='memes/%s.png' % meme_id)
    resultPath = memeviz.bound_image('.' + imagePath)
    analysisResult = subprocess.check_output('tesseract -l impact %s stdout' %
                                             resultPath,
                                             shell=True)
    return render_template('made_meme.html', image=image, text=analysisResult)
Exemplo n.º 8
0
def post_meme():
    template_id = request.form["template"]
    top = request.form["top"]
    bottom = request.form["bottom"]

    #TODO: create id is what None here is supposed to be
    meme_id = dao.create_meme(mongo.db,
                              template_id,
                              MemeText(top, bottom),
                              None)

    template_name = dao.get_template_filename(mongo.db, template_id)
    memegenerator.gen_meme(template_name, top, bottom, meme_id)

    return redirect(url_for("get_memes"))
Exemplo n.º 9
0
def meme(path):
    image_extensions = ('png', 'jpeg', 'jpg', 'gif')
    extensions = image_extensions + ('json', 'log')
    ext = 'jpg'
    if path.endswith(tuple('.%s' % e for e in extensions)):
        path_parts = path.split('.')
        path = ''.join(path_parts[:-1])
        ext = path_parts[-1]

    path_parts = path.split('/')
    while(len(path_parts) < 3):
        path_parts.append('')

    try:
        meme_name, top, bottom = tuple(path_parts)
    except ValueError:
        abort(404)

    meme_image = guess_meme_image(meme_name)
    top = replace_underscore(top)
    bottom = replace_underscore(bottom)

    if ext == 'log':
        return meme_image
    elif ext == 'json':
        return json.dumps({'image': meme_image, 'top': top, 'bottom': bottom})
    elif ext in image_extensions:
        meme_path = os.path.join(TEMPLATES_PATH, meme_image)
        meme_id = md5("%s|%s|%s" % (meme_image, top, bottom)).hexdigest()
        file_path = '%s.%s' % (meme_id, ext)
        try:
            open(MEME_PATH + file_path)
            app.logger.debug('file "%s" exists', file_path)
        except IOError:
            app.logger.info('Generating Meme')
            gen_meme(meme_path + '.jpg', top, bottom, MEME_PATH + file_path)

        return send_from_directory(MEME_PATH, file_path)