Browse Source

Image Handling gefixed

Und kleiner Cleanup
master
Eddie 2 years ago
parent
commit
cd267700af
  1. 14
      app.py
  2. BIN
      planet2.png
  3. 11
      planets.py
  4. BIN
      static/IMG/planet.png
  5. 3
      templates/index.html

14
app.py

@ -1,20 +1,22 @@
import os
from flask import Flask, render_template
from flask import Flask, render_template, send_file
from planets import createRandomPlanet
app = Flask(__name__)
IMG_FOLDER = os.path.join('static', 'IMG')
app.config['UPLOAD_FOLDER'] = IMG_FOLDER
@app.route('/')
def index():
planet = os.path.join(app.config['UPLOAD_FOLDER'], 'planet.png')
return render_template('index.html', planet=planet)
@app.route('/<seed>')
def hello(seed):
print(seed)
createRandomPlanet(seed)
planet = os.path.join(app.config['UPLOAD_FOLDER'], 'planet.png')
return render_template('hello.html', planet=planet)
return send_file(planet)
if __name__=='__main__':
app.run(debug=True, host='0.0.0.0')

BIN
planet2.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 434 KiB

11
planets.py

@ -1,7 +1,6 @@
import os, random
from PIL import Image
light_directory = os.fsencode(str(os.getcwd() + "/planets/light"))
noise_directory = os.fsencode(str(os.getcwd() + "/planets/noise"))
sphere_directory = os.fsencode(str(os.getcwd() + "/planets/sphere"))
@ -11,13 +10,12 @@ amount_noise = len(os.listdir(noise_directory))
amount_sphere = len(os.listdir(sphere_directory))
def changeImageColor(im, red, green, blue):
# Split into 3 channels
r, g, b, a = im.split()
# Change channel by factor
r = r.point(lambda i: i * red)
g = g.point(lambda i: i * green)
b = b.point(lambda i: i * blue)
# Recombine back to RGB image
result = Image.merge('RGBA', (r, g, b, a))
return result
@ -25,7 +23,6 @@ def changePlanetLayerColor(planetLayer):
red = random.uniform(-0.5,1.5)
green = random.uniform(-0.5,1.5)
blue = random.uniform(-0.5,1.5)
#print(red,green,blue)
changedColor = changeImageColor(planetLayer, red, green, blue)
return changedColor
@ -63,7 +60,3 @@ def createRandomPlanet(seed):
planet = mergePlanetParts(light, noise1, noise2, noise3, sphere)
planet.save("static/IMG/planet.png")
return
#planet = createRandomPlanet('Elijah')
#planet.save("planet2.png")

BIN
static/IMG/planet.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 378 KiB

After

Width:  |  Height:  |  Size: 443 KiB

3
templates/hello.html → templates/index.html

@ -2,9 +2,10 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hello Worl!</title>
<title>Planets</title>
</head>
<body>
<h1>Welcome to Planets</h1>
<img src="{{ planet }}" alt="Planet">
</body>
</html>
Loading…
Cancel
Save