Example #1
0
def upload_file():
    if request.method == 'POST':
        if 'file' not in request.files:
            return render_template('input.html',
                                   error="Select an image first.")
        file = request.files['file']
        if file.filename == '':
            return render_template('input.html',
                                   error="Select an image first.")
        if file:
            filename = secure_filename(file.filename)
            file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

            if checkifimage("static/img/input/" + filename):
                if request.form.get('type') == 'img':
                    img2img.main(str("static/img/input/" + filename),
                                 str("static/img/output/ASCII_" + filename),
                                 str(request.form.get('mode')),
                                 str(request.form.get('background')),
                                 int(request.form.get('num_cols')),
                                 int(request.form.get('scale')))
                    outputfilename = "/static/img/output/ASCII_" + filename
                    return render_template('result.html',
                                           type='img',
                                           output_file=outputfilename)
                else:
                    fname = os.path.splitext(filename)[0] + '.txt'
                    img2txt.main(str("static/img/input/" + filename),
                                 str("static/img/output/ASCII_" + fname),
                                 str(request.form.get('mode')),
                                 int(request.form.get('num_cols')),
                                 int(request.form.get('scale')))
                    outputfilename = "/static/img/output/ASCII_" + fname
                    return render_template('result.html',
                                           type='txt',
                                           output_file=outputfilename)

            else:
                return render_template('input.html',
                                       error="Unsupported file format.")
Example #2
0
def convert_image(imglink, conv_type, mode, bg, num_cols, scale):

    if (conv_type == 'img'):
        convertedImage, errors = img2img.main(imglink, mode, bg, num_cols,
                                              scale)

        responseObject = upload_image(base64.b64encode(convertedImage))

    elif (conv_type == 'txt'):
        convertedText, errors = img2txt.main(imglink, mode, num_cols, scale)

        responseObject = upload_text(convertedText)

    else:
        responseObject = {
            "result": {
                'mainResult': "none",
                'raw': "none",
                'dl': "none"
            },
            "errors": "conv_type not specified!"
        }

    return responseObject
Example #3
0
def main():
    # some bitmap related things need to have a wxApp initialized...
    if wx.GetApp() is None:
        global app
        app = wx.App()
    img2img.main(sys.argv[1:], wx.BITMAP_TYPE_PNG, ".png", __doc__)
Example #4
0
def main():
    # some bitmap related things need to have a wxApp initialized...
    if wx.GetApp() is None:
        global app
        app = wx.PySimpleApp()
    img2img.main(sys.argv[1:], wx.BITMAP_TYPE_XPM, ".xpm", __doc__)
Example #5
0
def main():
    # some bitmap related things need to have a wxApp initialized...
    if wx.GetApp() is None:
        app = wx.PySimpleApp()
    img2img.main(sys.argv[1:], wx.BITMAP_TYPE_XPM, ".xpm", __doc__)