import colorsys
from PIL import Image, ImageFont, ImageDraw


class TextRenderer:

    def __init__(self, font="./NotoSansCJK-Bold.otf",
                 font_color=(0, 120, 0), color_bg=False):
        self.image = None

        # params
        self.color_bg = color_bg
        self.font_color = font_color

        # new image and font
        self.font = ImageFont.truetype(font, 30)
        return None

    def getFrameCount(self):
        return 1

    def rainbow_bg(c):
        # hue, lightness, saturation to rgb
        vals = colorsys.hls_to_rgb(round(c / 360.0, 2), 0.05, 1)
        return (int(vals[0] * 255), int(vals[1] * 255), int(vals[2] * 255))

    def draw_text(self, text_to_send):
        x, y = self.font.getsize(text_to_send)

        self.im = Image.new("RGBA", (x, y+10), "black")
        # Add padding below, because PIL sucks!
        self.draw = ImageDraw.Draw(self.im)

        self.draw.text(
            (0, 0), text_to_send, font=self.font, fill=self.font_color
        )

    def render(self, msgText):
        self.draw_text(' '.join(msgText))

    def getImage(self):
        return self.image

    def get_queue_token(self, msgToken):
        queue_token = {}
        # TODO: add possible params
        self.render(msgToken["text"])
        queue_token["image"] = [self.im]
        queue_token["frame_count"] = self.getFrameCount()
        queue_token["action"] = "scroll"
        queue_token["valid"] = True

        return queue_token

@@ -1,20 +1,4 @@
-import colorsys%0A
 from
@@ -175,34 +175,8 @@
 se):
-%0A        self.image = None
 %0A%0A  
@@ -260,17 +260,16 @@
 t_color%0A
-%0A
         
@@ -342,724 +342,316 @@
 30)%0A
-        return None%0A%0A    def getFrameCount(self):%0A        return 1%0A%0A    def rainbow_bg(c):%0A        # hue, lightness, saturation to rgb%0A        vals = colorsys.hls_to_rgb(round(c / 360.0, 2), 0.05, 1)%0A        return (int(vals%5B0%5D * 255), int(vals%5B1%5D * 255), int(vals%5B2%5D * 255))%0A%0A    def draw_text(self, text_to_send):%0A        x, y = self.font.getsize(text_to_send)%0A%0A        self.im = Image.new(%22RGBA%22, (x, y+10), %22black%22)%0A        # Add padding below, because PIL sucks!%0A        self.draw = ImageDraw.Draw(self.im)%0A%0A        self.draw.text(%0A            (0, 0), text_to_send, font=self.font, fill=self.font_color%0A        )%0A%0A    def render(self, msgText):%0A        self.draw_text(' '.join(msgText))%0A%0A    def getImage(self):
+%0A    def draw_text(self, text_to_send):%0A        x, y = self.font.getsize(text_to_send)%0A%0A        # Add padding below, because PIL sucks!%0A        image = Image.new(%22RGBA%22, (x, y+10), %22black%22)%0A%0A        ImageDraw.Draw(image).text(%0A            (0, 0), text_to_send, font=self.font, fill=self.font_color%0A        )%0A
 %0A   
@@ -662,21 +662,16 @@
  return 
-self.
 image%0A%0A 
@@ -783,77 +783,74 @@
     
-self.render(msgToken%5B%22text%22%5D)%0A        queue_token%5B%22image%22%5D = %5Bself.im
+queue_token%5B%22image%22%5D = %5Bself.draw_text(' '.join(msgToken%5B%22text%22%5D))
 %5D%0A  
@@ -888,28 +888,9 @@
 %5D = 
-self.getFrameCount()
+1
 %0A   

Remove all unused code in text renderer.