56
edits
No edit summary |
No edit summary |
||
| (4 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
== | == Picturius Bottian Twitterbot == | ||
[[File:headerpictorius.JPG]] | |||
Twitterbot: [https://twitter.com/picturius @Picturus Bottian] | Twitterbot: [https://twitter.com/picturius @Picturus Bottian] | ||
'''What the Bot does:''' | |||
The Bot repost an filtered Image to you (if you send him one). Therefore he choose random 2-4 individual filter functions and create a new Image. He also give back a short sentence which he choose randomly. If you did not send and image and just text... he answer with: "No image". | |||
[[File:picturius02.JPG]] | |||
[[File:picturius03.JPG]] | |||
[[File:picturius04.JPG]] | |||
[[File:picturius05.JPG]] | |||
[[File:picturius06.JPG]] | |||
[[File:picturius07.JPG]] | |||
[[File:picturius08.JPG]] | |||
[[File:picturius09.JPG]] | |||
'''Ideas andP roblems:''' | |||
I want to do an image bot which is not 100% clear what he creates. So I play whith this random and filter functions. To get on every processed image an individual look i had to go more and more abstract whith his output. So I increase the numbers of filter functions, put in more distorted filters and increase the minimal number of filter routines on every image. | |||
'''Thanks to:''' | |||
Thanks to [http://stackoverflow.com/ Stackoverflow], thanks to the smaller Blogs and Forums I arrieved via Google, thanks to [http://effbot.org/ effbot], thanks to [https://pillow.readthedocs.org// Pillow] and last but not least thanks to Martin and Sebastian. | |||
'''The code:''' | |||
<source lang="python"> | |||
############################ | |||
############################ | |||
############################ | |||
### Main File ############## | |||
############################ | |||
############################ | |||
############################ | |||
#Import Classes + Modules | #Import Classes + Modules | ||
| Line 134: | Line 153: | ||
bot.run() | bot.run() | ||
############################ | |||
############################ | |||
############################ | |||
### Filter File ############ | |||
############################ | |||
############################ | |||
############################ | |||
from PIL import Image, ImageDraw, ImageFont, ImageFilter, ImageColor, ImageEnhance | from PIL import Image, ImageDraw, ImageFont, ImageFilter, ImageColor, ImageEnhance | ||
| Line 146: | Line 166: | ||
# | #Bildbearbeitungfunktionen | ||
def edges (image): #002 | |||
def edges (image): | |||
return image.filter(ImageFilter.FIND_EDGES) | return image.filter(ImageFilter.FIND_EDGES) | ||
def transpose(image): | def transpose(image): #002 | ||
return image.transpose(Image.FLIP_LEFT_RIGHT) | return image.transpose(Image.FLIP_LEFT_RIGHT) | ||
def invert(image): | def invert(image): #002 | ||
return image.point(lambda x: 255-x) | return image.point(lambda x: 255-x) | ||
def pixelit (image): | def pixelit (image): #001 | ||
xsize, ysize = image.size | xsize, ysize = image.size | ||
width = xsize | width = xsize | ||
| Line 173: | Line 187: | ||
return image | return image | ||
# | def blend (image): #001 | ||
image.convert("RGBA") | |||
imgrotate1 = image.rotate(135) | |||
imgrotate2 = image.rotate(225) | |||
image2 = Image.blend(imgrotate1, imgrotate2, 0.5) | |||
image = Image.blend(image, image2, 0.5) | |||
return image | |||
def nogreen (image): #001 | |||
image.convert("RGB") | |||
source = image.split() | |||
R, G, B = 0, 1, 2 | |||
out = source[G].point(lambda i: i*0.0) | |||
source[G].paste(out, None, None) | |||
image = Image.merge(image.mode, source) | |||
return image | |||
def colorchange (image) : #002 | |||
image.convert("RGB") | |||
source = image.split() | |||
R, G, B = 0, 1, 2 | |||
mask1 = source[R].point(lambda i: i<200 and 255) | |||
out1 = source[R].point(lambda i: i*0) | |||
source[R].paste(out1, None, mask1) | |||
mask2 = source[G].point(lambda i: i<200 and 255) | |||
out2 = source[G].point(lambda i: i*0.5) | |||
source[G].paste(out2, None, mask2) | |||
image = Image.merge(image.mode, source) | |||
return image | |||
def switchchannels (image) : #001 | |||
image.convert("RGB") | |||
r,g,b = image.split() | |||
image = Image.merge ("RGB", (g,b,r)) | |||
return image | |||
def pixelsort (image) : #002 | |||
source = image | |||
colors = source.getcolors(source.size[0] * source.size[1]) | |||
pixels = [] | |||
for i, color in colors: | |||
pixels.extend(i * [color]) | |||
pixels.sort() | |||
new = Image.new("RGB", source.size) | |||
new.putdata(pixels) | |||
image = new | |||
return image | |||
def pixelunsort (image) : #002 | |||
source = image | |||
colors = source.getcolors(source.size[0] * source.size[1]) | |||
pixels = [] | |||
for i, color in colors: | |||
pixels.extend(i * [color]) | |||
random.shuffle(pixels) | |||
new = Image.new("RGB", source.size) | |||
new.putdata(pixels) | |||
image = new | |||
return image | |||
def spectral (image) : #002 | |||
image2 = image | |||
image.convert("RGB") | |||
image = Image.new( "RGB", image.size, "black") | |||
pixels = image.load() | |||
for i in range (image.size[0]): | |||
for j in range (image.size[1]): | |||
pixels[i,j] = (i, j, 0) | |||
image = Image.blend(image, image2, 0.4) | |||
return image | |||
def pixelunsort_green (image) : #001 | |||
image.convert("RGB") | |||
source2 = image.split() | |||
R, G, B = 0, 1, 2 | |||
out1 = source2[R].point(lambda i: i*0.1) | |||
out2 = source2[B].point(lambda i: i*0.9) | |||
source2[R].paste(out1, None, None) | |||
source2[B].paste(out2, None, None) | |||
image = Image.merge(image.mode, source2) | |||
source = image | |||
colors = source.getcolors(source.size[0] * source.size[1]) | |||
pixels = [] | |||
for i, color in colors: | |||
pixels.extend(i * [color]) | |||
random.shuffle(pixels) | |||
new = Image.new("RGB", source.size) | |||
new.putdata(pixels) | |||
image = new | |||
return image | |||
def pixelsort_green (image) : #001 | |||
image.convert("RGB") | |||
source2 = image.split() | |||
R, G, B = 0, 1, 2 | |||
out1 = source2[R].point(lambda i: i*0.1) | |||
out2 = source2[B].point(lambda i: i*0.9) | |||
source2[R].paste(out1, None, None) | |||
source2[B].paste(out2, None, None) | |||
image = Image.merge(image.mode, source2) | |||
source = image | |||
colors = source.getcolors(source.size[0] * source.size[1]) | |||
pixels = [] | |||
for i, color in colors: | |||
pixels.extend(i * [color]) | |||
pixels.sort() | |||
new = Image.new("RGB", source.size) | |||
new.putdata(pixels) | |||
image = new | |||
return image | |||
#Random Filter List | |||
def filter (image): | def filter (image): | ||
functions_list = [ | functions_list = [edges, transpose, invert, pixelit, blend, nogreen, colorchange, switchchannels, pixelsort, pixelunsort, spectral, pixelunsort_green, pixelsort_green] | ||
filename = "final.png" | filename = "final.png" | ||
x = | x = 2 | ||
y = | y = 3 | ||
z = | z = 4 | ||
list = [x, y, z] | list = [x, y, z] | ||
anzahl = random.choice(list) | anzahl = random.choice(list) | ||
print (anzahl) | print (anzahl) | ||
if anzahl == | if anzahl == 2: | ||
#Random eine Funktion | #Random eine Funktion | ||
imagefunc = random.choice(functions_list) | |||
image = imagefunc(image) | |||
#2.Runde Random Filter anwenden | |||
imagefunc = random.choice(functions_list) | imagefunc = random.choice(functions_list) | ||
image = imagefunc(image) | image = imagefunc(image) | ||
if anzahl == | if anzahl == 3: | ||
#Random eine Funktion | #Random eine Funktion | ||
imagefunc = random.choice(functions_list) | imagefunc = random.choice(functions_list) | ||
image = imagefunc(image) | image = imagefunc(image) | ||
#2.Runde Random Filter anwenden | #2.Runde Random Filter anwenden | ||
imagefunc = random.choice(functions_list) | |||
image = imagefunc(image) | |||
#3.Runde Random Filter anwenden | |||
imagefunc = random.choice(functions_list) | imagefunc = random.choice(functions_list) | ||
image = imagefunc(image) | image = imagefunc(image) | ||
if anzahl == | if anzahl == 4: | ||
#Random eine Funktion | #Random eine Funktion | ||
imagefunc = random.choice(functions_list) | imagefunc = random.choice(functions_list) | ||
| Line 210: | Line 340: | ||
image = imagefunc(image) | image = imagefunc(image) | ||
#3.Runde Random Filter anwenden | #3.Runde Random Filter anwenden | ||
imagefunc = random.choice(functions_list) | |||
image = imagefunc(image) | |||
#4.Runde Random Filter anwenden | |||
imagefunc = random.choice(functions_list) | imagefunc = random.choice(functions_list) | ||
image = imagefunc(image) | image = imagefunc(image) | ||
| Line 215: | Line 348: | ||
return image | return image | ||
############################ | |||
############################ | |||
############################ | |||
### Text File ############## | |||
############################ | |||
############################ | |||
############################ | |||
#Import Modules for Project | #Import Modules for Project | ||
| Line 259: | Line 393: | ||
return text | return text | ||
</source> | |||
</ | |||
edits