Exemple #1
0
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')
Exemple #2
0
def poly():
    if request.method == 'POST':
        print(request.form)
        if request.form['side'] and request.form['np'] and (
                request.form['rgb1'] and request.form['rgb2']):
            side = int(request.form['side'])
            np = int(request.form['np'])

            rgb1 = request.form['rgb1'][1:]
            rgb2 = request.form['rgb2'][1:]

            error = None

            try:
                rgb1 = tuple(bytes.fromhex(rgb1))
                rgb2 = tuple(bytes.fromhex(rgb2))
            except Exception as e:
                if e:
                    error = "ERROR: Invalid color hex"

            print(side, np, rgb1, rgb2)

            if (side > 4000 and side >= 100) or side < 100:
                error = "WARNING: Image too large OR Image too small"
            if np < 10 or np > 300:
                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
                side += shift * 2
                points = wallgen.genPoints(np, side)
                img = wallgen.gradient(side, rgb1, rgb2)
                img = wallgen.genWall(img, points, side, shift)
                print(fpath)
                img.save(fpath)
                imgurl = url_for('static', filename='images/' + fname)
                return render_template("download.html", context=imgurl)
        else:
            error = "Invalid input, try again"
            return render_template("error.html", context=error)
    else:
        return render_template('poly.html')
Exemple #3
0
def poly():
	if request.method == 'POST':
		print(request.form)
		if request.form['side'] and request.form['np'] and (request.form['rgb1'] and request.form['rgb2']):
			side = int(request.form['side'])
			np = int(request.form['np'])
			
			rgb1 = request.form['rgb1'][1:]
			rgb2 = request.form['rgb2'][1:]

			error = None
			
			try:
				rgb1 = tuple(bytes.fromhex(rgb1))
				rgb2 = tuple(bytes.fromhex(rgb2))
			except Exception as e:
				if e:
					error = "ERROR: Invalid color hex"
			
			print(side, np, rgb1, rgb2)
			
			if (side > 4000 and side >= 100) or side < 100:
				error = "WARNING: Image too large OR Image too small"
			if np < 10 or np > 300:
				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
				side += shift*2
				points = wallgen.genPoints(np, side)
				img = wallgen.gradient(side, rgb1, rgb2)
				img = wallgen.genWall(img, points, side, shift)
				print(fpath)
				img.save(fpath)
				imgurl = url_for('static',filename='images/'+fname)
				return render_template("download.html", context=imgurl)
		else:
			error = "Invalid input, try again"
			return render_template("error.html", context=error)
	else:
		return render_template('poly.html')
Exemple #4
0
def download():
    if request.method == 'POST':
        print(request.form)
        if request.form['side'] and request.form['np'] and (
                request.form['rgb1'] and request.form['rgb2']):
            side = int(request.form['side'])
            np = int(request.form['np'])

            rgb1 = request.form['rgb1'][1:]
            rgb2 = request.form['rgb2'][1:]

            error = None

            try:
                rgb1 = tuple(bytes.fromhex(rgb1))
                rgb2 = tuple(bytes.fromhex(rgb2))
            except Exception as e:
                if e:
                    error = "ERROR: Invalid color hex"

            print(side, np, rgb1, rgb2)

            if (side > 4000 and side >= 100) or side < 100:
                error = "WARNING: Image too large OR Image too small"
            if np < 10 or np > 300:
                error = "WARNING: Too less points OR too many points"

            if error != None:
                print(error)
                return error, 403
            else:
                fname = "wall-{}.png".format(int(time.time()))
                fpath = 'static/images/' + fname
                shift = side // 10
                side += shift * 2
                points = wallgen.genPoints(np, side)
                img = wallgen.gradient(side, rgb1, rgb2)
                img = wallgen.genWall(img, points, side, shift)
                print(fpath)
                img.save(fpath)
                imgurl = url_for('static', filename='images/' + fname)
                return "http://wallgen.herokuapp.com/" + fpath
Exemple #5
0
def download():
	if request.method == 'POST':
		print(request.form)
		if request.form['side'] and request.form['np'] and (request.form['rgb1'] and request.form['rgb2']):
			side = int(request.form['side'])
			np = int(request.form['np'])
			
			rgb1 = request.form['rgb1'][1:]
			rgb2 = request.form['rgb2'][1:]

			error = None
			
			try:
				rgb1 = tuple(bytes.fromhex(rgb1))
				rgb2 = tuple(bytes.fromhex(rgb2))
			except Exception as e:
				if e:
					error = "ERROR: Invalid color hex"
			
			print(side, np, rgb1, rgb2)
			
			if (side > 4000 and side >= 100) or side < 100:
				error = "WARNING: Image too large OR Image too small"
			if np < 10 or np > 300:
				error = "WARNING: Too less points OR too many points"

			if error != None:
				print(error)
				return error, 403
			else:
				fname = "wall-{}.png".format(int(time.time()))
				fpath = 'static/images/'+fname
				shift = side//10
				side += shift*2
				points = wallgen.genPoints(np, side)
				img = wallgen.gradient(side, rgb1, rgb2)
				img = wallgen.genWall(img, points, side, shift)
				print(fpath)
				img.save(fpath)
				imgurl = url_for('static',filename='images/'+fname)
				return "http://wallgen.herokuapp.com/"+fpath
Exemple #6
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)
                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")
Exemple #7
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")