예제 #1
0
파일: app.py 프로젝트: gridl/wallgen
def poly():
	if request.method == 'POST':
		# get data

		side = int(request.form.get('side'))
		np = int(request.form.get('np'))

		outline = request.form.get('outline')
		
		nColors = request.form.get('nColors')
		# print(nColors)

		colors = []

		for i in range(int(nColors)):
			colors.append(request.form.get('rgb'+str(i+1)))

		error = None
		
		try:
			colors = [tuple(bytes.fromhex(x[1:])) for x in colors]
		except Exception as e:
			print(e)
			error = "ERROR: Invalid color hex"
		
		if side > 5000 or side < 100:
			error = "WARNING: Image too large OR Image too small"
		if np < 10 or np > 1000:
			error = "WARNING: Too less points OR too many points"

		if error != None:
			print(error)
			return render_template('error.html', context=error)
		else:
			fname = "wall-{}.png".format(int(time.time()))
			fpath = 'static/images/'+fname
			
			shift = side//10
			nside = side + shift*2 # increase size to prevent underflow

			img = wallgen.nGradient(side, *colors)

			pts = wallgen.genPoints(np, nside, nside)
			img = wallgen.genPoly(side, side, img, pts, shift, shift, outl=outline)

			# print(fpath)
			img.save(fpath)

			imgurl = url_for('static',filename='images/'+fname)
			return render_template("download.html", context=imgurl, home="poly")
	else:
		return render_template('poly.html')
예제 #2
0
파일: app.py 프로젝트: pablorgr/wallgen
def pic():
    if request.method == 'POST':
        # print(request.files)
        # print(request.form)
        if 'image' not in request.files:
            error = "No file part"
            return render_template("error.html", context=error)
        else:
            file = request.files['image']
            # print(file.filename)
            # print(len(file.filename))
            if len(file.filename) < 1:
                error = "No file selected"
                return render_template("error.html", context=error)

            if file and allowed_file(file.filename):
                filename = secure_filename(file.filename)
                ufpath = os.path.join(app.config['UPLOAD_FOLDER'], filename)
                file.save(ufpath)
                np = request.form.get('np')
                outline = request.form.get('outline')
                smart = request.form.get('smart')

                if np or smart:
                    og_img = Image.open(ufpath)
                    width = og_img.width
                    height = og_img.height

                    if min(height, width) > 1080:
                        scale = min(height, width) // 1080
                    else:
                        scale = 1
                    img = og_img.resize(
                        (width // scale, height // scale),
                        resample=Image.BICUBIC)
                    width = img.width
                    height = img.height
                    wshift = width // 100
                    hshift = height // 100

                    n_width = width + 2 * wshift
                    n_height = height + 2 * height

                    if outline:
                        outline = tuple(bytes.fromhex("#2c2c2c"[1:]))
                    else:
                        outline = None

                    if smart:
                        ski_img = io.imread(ufpath, True)
                        gray_img = color.rgb2gray(ski_img)
                        pts = genSmartPoints(gray_img)
                    else:
                        pts = genPoints(int(np), n_width, n_height)

                    img = genPoly(img.width, img.height, img, pts,
                                  wshift, hshift, outline, pic=True)

                    fname = "wall-{}.png".format(int(time.time()))
                    fpath = 'static/images/' + fname

                    # print(fpath)
                    img.save(fpath)
                    imgurl = url_for('static', filename='images/' + fname)
                    return render_template(
                        "download.html", context=imgurl, home="pic")
                else:
                    error = "Invalid input, try again"
                    return render_template("error.html", context=error)
            else:
                error = "filetype not allowed"
                return render_template("error.html", context=error)
    else:
        return render_template("pic.html")
예제 #3
0
def pic():
    if request.method == 'POST':
        # print(request.files)
        # print(request.form)
        if 'image' not in request.files:
            error = "No file part"
            return render_template("error.html", context=error)
        else:
            file = request.files['image']
            # print(file.filename)
            # print(len(file.filename))
            if len(file.filename) < 1:
                error = "No file selected"
                return render_template("error.html", context=error)

            if file and allowed_file(file.filename):
                filename = secure_filename(file.filename)
                ufpath = os.path.join(app.config['UPLOAD_FOLDER'], filename)
                file.save(ufpath)
                if request.form.get('np'):
                    np = request.form.get('np')
                    outline = request.form.get('outline')

                    img = Image.open(ufpath)
                    width = img.width
                    height = img.height
                    wshift = img.width // 10
                    hshift = img.height // 10
                    width += wshift * 2
                    height += hshift * 2

                    if outline:
                        outline = tuple(bytes.fromhex("#2c2c2c"[1:]))
                    else:
                        outline = None

                    pts = wallgen.genPoints(int(np), width, height)
                    img = wallgen.genPoly(img.width,
                                          img.height,
                                          img,
                                          pts,
                                          wshift,
                                          hshift,
                                          outline,
                                          pic=True)

                    fname = "wall-{}.png".format(int(time.time()))
                    fpath = 'static/images/' + fname

                    # print(fpath)
                    img.save(fpath)
                    imgurl = url_for('static', filename='images/' + fname)
                    return render_template("download.html",
                                           context=imgurl,
                                           home="pic")
                else:
                    error = "Invalid input, try again"
                    return render_template("error.html", context=error)
            else:
                error = "filetype not allowed"
                return render_template("error.html", context=error)
    else:
        return render_template("pic.html")