GMU:Bots 'n' Plots/Constantin Oestreich: Difference between revisions

From Medien Wiki
(Midtermbot)
No edit summary
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
==== Page of Constantin Oestreich ====
== Picturius Bottian Twitterbot ==
[[File:headerpictorius.JPG]]


Twitter: [https://twitter.com/ConstOest @ConstOest]
Twitterbot: [https://twitter.com/picturius @Picturus Bottian]


[[File:Robot_const.jpg]]
'''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".  


==== Animated Robot ====
[[File:picturius02.JPG]]
[[File:picturius03.JPG]]
[[File:picturius04.JPG]]
[[File:picturius05.JPG]]
[[File:picturius06.JPG]]
[[File:picturius07.JPG]]
[[File:picturius08.JPG]]
[[File:picturius09.JPG]]


[[File:Robot_Const.gif]]


Thumb doesnt work - find it here:
'''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.


Animated Robot: [https://www.uni-weimar.de/medien/wiki/images/Robot_Const.gif]
'''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.


==== Robot Code ====
'''The code:'''
<source lang="python">
############################
############################
############################
### Main File ##############
############################
############################
############################


<pre style="font-size:smaller" >
#Import Classes + Modules


"""
from twitterbot import TwitterBot
import keys
import random
from io import BytesIO
from PIL import Image
from image import get_image_file


My Animated Robot
#Import aus Dateien
from textposts import make_text
from textposts import no_image
from imagefuncs import filter


"""


#Variablen
############################
### Twitterbot functions ###
############################


widthBox = 400
class MyTwitterBot(TwitterBot):
heightBox = widthBox
   
centerx = widthBox / 2
    # Keys
centery = heightBox / 2
    def bot_init(self):
koerper = widthBox / 3
        """ Initialize and configure the bot """
kopf = koerper / 1.5
auge = kopf / 6
blauKopf = 0
gruenKopf = 90
rotKopf = 100


        ############################
        # REQUIRED: LOGIN DETAILS! #
        ############################
        self.config['api_key'] = keys.consumer_key
        self.config['api_secret'] = keys.consumer_secret
        self.config['access_key'] = keys.access_token
        self.config['access_secret'] = keys.access_token_secret




#Ausgabe
        ######################################
        # SEMI-OPTIONAL: OTHER CONFIG STUFF! #
        ######################################


def setup():
        # how often to tweet, in seconds
    size (widthBox,heightBox)
        self.config['tweet_interval'] = 1 * 5     # default: 1 minutes
     colorMode (RGB, 100)


        # use this to define a (min, max) random range of how often to tweet
        # e.g., self.config['tweet_interval_range'] = (5*60, 10*60) # tweets every 5-10 minutes
        self.config['tweet_interval_range'] = None


def draw():
        # only reply to tweets that specifically mention the bot
   
         self.config['reply_direct_mention_only'] = True
    #Moving per Frame
    frameRate (25)
    angle = PI/8 * sin(frameCount * 0.1)
   
    #Growing Up
   
    global auge
    if auge<30:
        auge=auge+2
    else:
        auge=10
       
    global kopf
    if kopf<140:
         kopf=kopf+2
    else:
        kopf = koerper / 1.5
       
    global blauKopf
    global gruenKopf
    global rotKopf   
    if kopf>koerper / 1.5 and kopf<130:
        blauKopf = blauKopf + 5
        gruenKopf = gruenKopf -2
        rotKopf = rotKopf -2
   
    elif kopf > 130 and kopf < 140:
        blauKopf = 0
        gruenKopf = 0
        rotKopf = 100
       
    else:
        blauKopf=0
        gruenKopf = 90
        rotKopf = 100 
   
    #Variablen BG
    R = random(30,60)
    G = random(50,80)
    B = random(70,90)
   
    #Variablen Fill
    RF = random(20,50)
    GF = random(0,30)
    BF = random(10,40)
   
    #define
    background(R,G,B)
    rectMode(CENTER)
    fill (RF,GF,BF)
    stroke (90)
    strokeWeight(5)   


    #---Körper---
        # only include bot followers (and original tweeter) in @-replies
    rect (centerx, centery, koerper, koerper)
        self.config['reply_followers_only'] = False


    #---Kopf---
        # fav any tweets that mention this bot?
    pushStyle()
        self.config['autofav_mentions'] = False
    fill (rotKopf, gruenKopf, blauKopf)
    ellipse (centerx, centery-koerper+(kopf*0.25), kopf, kopf)
    popStyle()
   
    # Variablen Auge
   
    AugeX1 = centerx - 17
    AugeY1 = centerx - koerper*0.875
    AugeX2 = centerx + 17
    AugeY2 = centerx - koerper*0.875
   
    #---Auge01---
   
    drawAuge(AugeX1, AugeY1, 1)
   
   
    #---Auge02---
   
    drawAuge(AugeX2, AugeY2, -1)
   
    # Arm positions
    posLx = centerx - koerper / 2
    posLy = centery - koerper / 2
    posRx = centerx + koerper / 2
    posRy = centery - koerper / 2
   
    # Bein positions
    posBLx = centerx - koerper / 2
    posBLy = centery + koerper / 2
    posBRx = centerx + koerper / 2
    posBRy = centery + koerper / 2
   
    #---Left Arm---
    drawArm(posLx-30, posLy-15, 1, angle)
   
    #---Right Arm---
    drawArm(posRx+30, posRy-15, -1, angle)
   
    #---Bein Links---
    drawBein(posBLx, posBLy)
   
    #---Bein Rechts---
    drawBein(posBRx-40, posBRy)
 
     
#Eigene Funktionen


def drawAuge (xpos, ypos, direction):
        # fav any tweets containing these keywords?
    pushMatrix()
        self.config['autofav_keywords'] = []
    pushStyle()
    fill (80,80,100)
    stroke (40)
    strokeWeight(2)
    translate (xpos, ypos) 
    scale(direction,1)
    ellipse (0,0,auge,auge) 
    popStyle()         
    popMatrix()


def drawArm (xpos, ypos, direction, angle):
        # follow back all followers?
    pushMatrix()
        self.config['autofollow'] = False
    translate(xpos,ypos)
    scale(direction,1)
    rotate(angle)
    rectMode(CORNER)
    rect(0,0,30,130)
    popMatrix()
   
def drawBein (xpos, ypos):
    pushMatrix()
    pushStyle()
    fill(10,10,40)
    translate(xpos,ypos)
    rectMode(CORNER)
    rect(0,0,40,90)
    popMatrix()
    popStyle()
   
   
    saveFrame("robot_const_###.png")
   
</pre>




==== Midtermbot ====
    def on_scheduled_tweet(self):
        """ Make a public tweet to the bot's own timeline. """
        # We might take senteces from somewhere and tweet them on a regular basis ...
        pass # don't do anything here ...


<pre style="font-size:smaller" >
    def on_mention(self, tweet, prefix):
        if tweet:
            # get image from tweet
            try:
                image_file = get_image_file(tweet)


"""
                if image_file is None:
                    text = ("{},"+no_image()).format(prefix)
                else:
                    # create a tweet and make sure to cut it off at 140 chars
                    text = ("{},"+make_text()).format(prefix)


midtermbot.py
            except Exception as e:
                    print(e)


"""
            # do the tweeting based on wether we have an image
            tweetsize = 140 - len(prefix) - 1
            text = text[:140]


###Import###


#Import Modules for Project
            if image_file is None:
from PIL import Image, ImageDraw, ImageFont, ImageFilter, ImageColor
import tweepy
import time
import random
import requests
from io import BytesIO


#Import aus Dateien
                    print("No Image")
from twitterkeys import *
                    self.post_tweet(text, reply_to=tweet)
from textposts import text
                    return
from imagefuncs import blur, emboss, edges, invert, transpose


##############
            else:
###Programm###
                filename, file = image_file
##############
                img = Image.open(file)
                img = filter(img)
                format = filename.split(".", 1)[1].upper()
                print("Image format: {}".format(format))
                output = BytesIO()
                img.save(output, format="PNG")
               
            try:
                # Post
               
                self.post_tweet(text, reply_to=tweet, media=filename, file=output)


###Twitter connect###
                output.close()


#TwitterPassVariable for Test without posting on Twitter
            except Exception as e:
#True = Post on Twitter / False = just open Image and show text local
                # did anything go wrong when we tried to create and post the tweet?
check = False
                print(e)
   
    def on_timeline(self, tweet, prefix):
        """ Actions to take on a timeline tweet. """
        pass # Don't do anything here ...


#Define TwitterKeys to variables
if __name__ == '__main__':
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
    bot = MyTwitterBot()
auth.secure = True
    bot.run()
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)


#Find Images and URL in Account on Twitter
timeline = api.user_timeline(screen_name = "C64_Bot")
for tweet in timeline:
  for media in tweet.entities.get("media",[{}]):
    if media.get("type",None) == "photo":
        url = media["media_url"]


###Load Image from URL###
############################
#"http://maui.hawaii.edu/tlc/wp-content/uploads/sites/53/2013/11/testing.jpg"
############################
response = requests.get(url)
############################
image = Image.open(BytesIO(response.content))
### Filter File ############
############################
############################
############################


#Test Bild laden
from PIL import Image, ImageDraw, ImageFont, ImageFilter, ImageColor, ImageEnhance
#image = Image.open("test.png")
import random


#Liste der verschiedenen Funktionen erstellen
functions_list = [blur, emboss, edges, invert, transpose]


#Mainfunction
#Bildbearbeitungfunktionen
if __name__ == "__main__":   
   
    #Random eine Funktion aufrufen
    imagefunc = random.choice(functions_list)
    #Random Funktion anwenden
    image = imagefunc(image)
   
    #2.Runde Random Filter anwenden
    #Random eine Funktion aufrufen
    imagefunc = random.choice(functions_list)
    #Random Funktion anwenden
    image = imagefunc(image)
   
    if check == True:
        filename = "final.png"
        image.save(filename)
        api.update_with_media(filename,text) 
   
    else:
        image.show()
        print(text)
</pre>


def edges (image): #002
    return image.filter(ImageFilter.FIND_EDGES)


<pre style="font-size:smaller" >
def transpose(image): #002
    return image.transpose(Image.FLIP_LEFT_RIGHT)


"""
def invert(image): #002
    return image.point(lambda x: 255-x)


imagefuncs.py
def pixelit (image): #001
    xsize, ysize = image.size
    width = xsize
    height = ysize
    minwidth = int(xsize * 0.05)
    minheight = int(ysize * 0.05)
    image = image.resize((minwidth, minheight) , Image.NEAREST)
    image = image.resize((width , height), Image.NEAREST)
    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


from PIL import Image, ImageDraw, ImageFont, ImageFilter, ImageColor, ImageEnhance
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


#verschiedene Bildbearbeitungfunktionen
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


#Bild blur
def pixelunsort (image) : #002
def blur (image):
     source = image
     return image.filter(ImageFilter.BLUR)
    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 emboss (image):
def spectral (image) : #002
     return image.filter(ImageFilter.EMBOSS)
    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 edges (image):
def pixelunsort_green (image) : #001
     return image.filter(ImageFilter.FIND_EDGES)
     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 transpose(image):
def pixelsort_green (image) : #001
     return image.transpose(Image.FLIP_LEFT_RIGHT)
     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


def invert(image):
    return image.point(lambda x: 255-x)


</pre>
#Random Filter List


def filter (image):


<pre style="font-size:smaller" >
    functions_list = [edges, transpose, invert, pixelit, blend, nogreen, colorchange, switchchannels, pixelsort, pixelunsort, spectral, pixelunsort_green, pixelsort_green]
    filename = "final.png"
   
    x = 2
    y = 3
    z = 4
    list = [x, y, z]
    anzahl = random.choice(list)
    print (anzahl)
   
    if anzahl == 2:
        #Random eine Funktion
        imagefunc = random.choice(functions_list)
        image = imagefunc(image)
        #2.Runde Random Filter anwenden
        imagefunc = random.choice(functions_list)
        image = imagefunc(image)
       
    if anzahl == 3:
        #Random eine Funktion
        imagefunc = random.choice(functions_list)
        image = imagefunc(image)
        #2.Runde Random Filter anwenden
        imagefunc = random.choice(functions_list)
        image = imagefunc(image)
        #3.Runde Random Filter anwenden
        imagefunc = random.choice(functions_list)
        image = imagefunc(image)
       
    if anzahl == 4:
        #Random eine Funktion
        imagefunc = random.choice(functions_list)
        image = imagefunc(image)
        #2.Runde Random Filter anwenden
        imagefunc = random.choice(functions_list)
        image = imagefunc(image)
        #3.Runde Random Filter anwenden
        imagefunc = random.choice(functions_list)
        image = imagefunc(image)
        #4.Runde Random Filter anwenden
        imagefunc = random.choice(functions_list)
        image = imagefunc(image)
   
    return image


"""


textposts.py
############################
 
############################
"""
############################
### Text File ##############
############################
############################
############################


#Import Modules for Project
#Import Modules for Project
Line 317: Line 361:




#Verschiedene Texte die gepostet werden können
def make_text():
a="Yeah, a new Image is Ready"
    a="Yeah, a new Image is Ready"
b="I'am an artist.What you think about?"
    b="What do you think about?"
c="Uh, which great Effekt"
    c="Uh, which Effekt"
d="Nice"
    d="Nice"
e="Thats what I do"
    e="Thats what I do"
f="Mhmmm, what you mean? Is this art?"
    f="Mhmmm, what you mean?"
g="Yes I post"
    g="My next I post!"
h="I should do an exhibition whith this works."
    h="I should do more of this."
i="Tell me what you think about."
    i="Twitter is my life."
j="This is my job! Post Pictures..."
    j="This is my job!"
k="Funky..."
    k="Funky"


    text_list = [a, b, c, d, e, f, g, h, i, j, k]
   
    text = random.choice(text_list)
   
    return text


#Liste mit allen Textinhalten erstellen
def no_image():
text_list = [a, b, c, d, e, f, g, h, i, j, k]
    a = "No Image there"
 
    b = "What you do? Where is my Image?"
 
    c = "I can't read! Send me a picture"
#Zufällige auswahl eines Inhalts
    d = "I like Images!"
text = random.choice(text_list)
    e = "Boring!"
 
    f = "Okay, I don't know what you want!"
</pre>
    g = "Pictures! Thats what I want!"
    noimagelist = [a, b, c, d, e, f, g]
   
    text = random.choice(noimagelist)
   
    return text
</source>

Latest revision as of 21:40, 17 October 2015

Picturius Bottian Twitterbot

Headerpictorius.JPG

Twitterbot: @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".

Picturius02.JPG Picturius03.JPG Picturius04.JPG Picturius05.JPG Picturius06.JPG Picturius07.JPG Picturius08.JPG 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 Stackoverflow, thanks to the smaller Blogs and Forums I arrieved via Google, thanks to effbot, thanks to Pillow and last but not least thanks to Martin and Sebastian.

The code:

############################
############################
############################
### Main File ##############
############################
############################
############################

#Import Classes + Modules

from twitterbot import TwitterBot
import keys
import random
from io import BytesIO
from PIL import Image
from image import get_image_file

#Import aus Dateien
from textposts import make_text
from textposts import no_image
from imagefuncs import filter


############################
### Twitterbot functions ###
############################

class MyTwitterBot(TwitterBot):
    
    # Keys
    def bot_init(self):
        """ Initialize and configure the bot """

        ############################
        # REQUIRED: LOGIN DETAILS! #
        ############################
        self.config['api_key'] = keys.consumer_key
        self.config['api_secret'] = keys.consumer_secret
        self.config['access_key'] = keys.access_token
        self.config['access_secret'] = keys.access_token_secret


        ######################################
        # SEMI-OPTIONAL: OTHER CONFIG STUFF! #
        ######################################

        # how often to tweet, in seconds
        self.config['tweet_interval'] = 1 * 5     # default: 1 minutes

        # use this to define a (min, max) random range of how often to tweet
        # e.g., self.config['tweet_interval_range'] = (5*60, 10*60) # tweets every 5-10 minutes
        self.config['tweet_interval_range'] = None

        # only reply to tweets that specifically mention the bot
        self.config['reply_direct_mention_only'] = True

        # only include bot followers (and original tweeter) in @-replies
        self.config['reply_followers_only'] = False

        # fav any tweets that mention this bot?
        self.config['autofav_mentions'] = False

        # fav any tweets containing these keywords?
        self.config['autofav_keywords'] = []

        # follow back all followers?
        self.config['autofollow'] = False


    def on_scheduled_tweet(self):
        """ Make a public tweet to the bot's own timeline. """
        # We might take senteces from somewhere and tweet them on a regular basis ...
        pass # don't do anything here ...

    def on_mention(self, tweet, prefix):
        if tweet:
            # get image from tweet
            try:
                image_file = get_image_file(tweet)

                if image_file is None:
                    text = ("{},"+no_image()).format(prefix)
                else:
                    # create a tweet and make sure to cut it off at 140 chars
                    text = ("{},"+make_text()).format(prefix)

            except Exception as e:
                    print(e)

            # do the tweeting based on wether we have an image
            tweetsize = 140 - len(prefix) - 1
            text = text[:140]


            if image_file is None:

                    print("No Image")
                    self.post_tweet(text, reply_to=tweet)
                    return

            else:
                filename, file = image_file
                img = Image.open(file)
                img = filter(img)
                format = filename.split(".", 1)[1].upper()
                print("Image format: {}".format(format))
                output = BytesIO()
                img.save(output, format="PNG")
                
            try:
                # Post
                
                self.post_tweet(text, reply_to=tweet, media=filename, file=output)

                output.close()

            except Exception as e:
                # did anything go wrong when we tried to create and post the tweet?
                print(e)
    
    def on_timeline(self, tweet, prefix):
        """ Actions to take on a timeline tweet. """
        pass # Don't do anything here ...

if __name__ == '__main__':
    bot = MyTwitterBot()
    bot.run()


############################
############################
############################
### Filter File ############
############################
############################
############################

from PIL import Image, ImageDraw, ImageFont, ImageFilter, ImageColor, ImageEnhance
import random


#Bildbearbeitungfunktionen

def edges (image): #002
    return image.filter(ImageFilter.FIND_EDGES)

def transpose(image): #002
    return image.transpose(Image.FLIP_LEFT_RIGHT)

def invert(image): #002
    return image.point(lambda x: 255-x)

def pixelit (image): #001
    xsize, ysize = image.size
    width = xsize
    height = ysize
    minwidth = int(xsize * 0.05)
    minheight = int(ysize * 0.05)
    image = image.resize((minwidth, minheight) , Image.NEAREST)
    image = image.resize((width , height), Image.NEAREST)
    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):

    functions_list = [edges, transpose, invert, pixelit, blend, nogreen, colorchange, switchchannels, pixelsort, pixelunsort, spectral, pixelunsort_green, pixelsort_green]
    filename = "final.png"
    
    x = 2
    y = 3
    z = 4
    list = [x, y, z]
    anzahl = random.choice(list)
    print (anzahl)
    
    if anzahl == 2:
        #Random eine Funktion
        imagefunc = random.choice(functions_list)
        image = imagefunc(image)
        #2.Runde Random Filter anwenden
        imagefunc = random.choice(functions_list)
        image = imagefunc(image)
        
    if anzahl == 3:
        #Random eine Funktion
        imagefunc = random.choice(functions_list)
        image = imagefunc(image)
        #2.Runde Random Filter anwenden
        imagefunc = random.choice(functions_list)
        image = imagefunc(image)
        #3.Runde Random Filter anwenden
        imagefunc = random.choice(functions_list)
        image = imagefunc(image)
        
    if anzahl == 4:
        #Random eine Funktion
        imagefunc = random.choice(functions_list)
        image = imagefunc(image)
        #2.Runde Random Filter anwenden
        imagefunc = random.choice(functions_list)
        image = imagefunc(image)
        #3.Runde Random Filter anwenden
        imagefunc = random.choice(functions_list)
        image = imagefunc(image)
        #4.Runde Random Filter anwenden
        imagefunc = random.choice(functions_list)
        image = imagefunc(image)
    
    return image


############################
############################
############################
### Text File ##############
############################
############################
############################

#Import Modules for Project
import random


def make_text():
    a="Yeah, a new Image is Ready"
    b="What do you think about?"
    c="Uh, which Effekt"
    d="Nice"
    e="Thats what I do"
    f="Mhmmm, what you mean?"
    g="My next I post!"
    h="I should do more of this."
    i="Twitter is my life."
    j="This is my job!"
    k="Funky"

    text_list = [a, b, c, d, e, f, g, h, i, j, k]
    
    text = random.choice(text_list)
    
    return text

def no_image():
    a = "No Image there"
    b = "What you do? Where is my Image?"
    c = "I can't read! Send me a picture"
    d = "I like Images!"
    e = "Boring!"
    f = "Okay, I don't know what you want!"
    g = "Pictures! Thats what I want!"
    noimagelist = [a, b, c, d, e, f, g]
    
    text = random.choice(noimagelist)
    
    return text