Implemented RGB color in design

This commit is contained in:
Maximilian Giller 2019-02-28 22:19:33 +01:00
parent 6af80788e8
commit b28341ada5
5 changed files with 17 additions and 24 deletions

View file

@ -8,16 +8,16 @@ path = ''
wpath = path+'weather-icons/' wpath = path+'weather-icons/'
opath = path+'other/' opath = path+'other/'
weekday = im_open(opath+'weekday.bmp').convert('L') weekday = im_open(opath+'weekday.bmp').convert('RGB')
eventicon = im_open(opath+'event.bmp').convert('L') eventicon = im_open(opath+'event.bmp').convert('RGB')
dateicon = im_open(opath+'today.bmp').convert('L') dateicon = im_open(opath+'today.bmp').convert('RGB')
tempicon = im_open(opath+'temperature.jpeg') tempicon = im_open(opath+'temperature.jpeg')
humicon = im_open(opath+'humidity.jpeg') humicon = im_open(opath+'humidity.jpeg')
seperator = im_open(opath+'seperator.jpeg').convert('L') seperator = im_open(opath+'seperator.jpeg').convert('RGB')
no_response= im_open(opath+'cloud-no-response.jpeg') no_response= im_open(opath+'cloud-no-response.jpeg')
sunriseicon = im_open(opath+'wi-sunrise.jpeg') sunriseicon = im_open(opath+'wi-sunrise.jpeg')
sunseticon = im_open(opath+'wi-sunset.jpeg') sunseticon = im_open(opath+'wi-sunset.jpeg')
windicon = im_open(opath+'wi-strong-wind.jpeg')# windicon = im_open(opath+'wi-strong-wind.jpeg')
datetime_locals = { datetime_locals = {
"de" : "de_DE.UTF-8", "de" : "de_DE.UTF-8",

View file

@ -4,13 +4,12 @@ from PIL import ImageDraw, ImageOps
class BoxDesign (DesignEntity): class BoxDesign (DesignEntity):
"""Redefinition of ImageDraw.Draw.Rectangle""" """Redefinition of ImageDraw.Draw.Rectangle"""
def __init__(self, size, fill=None, outline=None, width=0): def __init__(self, size, fill=None, outline=None, width=0):
super(BoxDesign, self).__init__((size[0]+1, size[1]+1)) super(BoxDesign, self).__init__((size[0]+1, size[1]+1), mask=True)
self.size = size self.size = size
self.__define_corners__() self.__define_corners__()
self.fill = fill self.fill = fill
self.outline = outline self.outline = outline
self.width = width self.width = width
self.is_bitmap = True
def __define_corners__(self): def __define_corners__(self):
topleft = (0,0) topleft = (0,0)
@ -22,7 +21,6 @@ class BoxDesign (DesignEntity):
def __finish_image__ (self): def __finish_image__ (self):
for i in range(self.width): for i in range(self.width):
ImageDraw.Draw(self.__image__).polygon(self.__get_reduced_corners__(i), fill=self.fill, outline=self.outline) ImageDraw.Draw(self.__image__).polygon(self.__get_reduced_corners__(i), fill=self.fill, outline=self.outline)
self.__image__ = ImageOps.invert(self.__image__)
def __get_reduced_corners__(self, reducer): def __get_reduced_corners__(self, reducer):
topleft = (reducer, reducer) topleft = (reducer, reducer)

View file

@ -3,30 +3,27 @@ from PIL import Image, ImageOps, ImageDraw
class DesignEntity (object): class DesignEntity (object):
"""General entity that can be drawn on to a panel design or """General entity that can be drawn on to a panel design or
other design entities.""" other design entities."""
def __init__ (self, size): def __init__ (self, size, mask=False):
self.size = size self.size = size
self.pos = (0, 0) self.pos = (0, 0)
self.mask = mask
self.__init_image__() self.__init_image__()
self.is_bitmap = False
def __init_image__ (self, color = 'white'): def __init_image__ (self, color = 'white'):
self.__image__ = Image.new('L', self.size, color=color) self.__image__ = Image.new('RGB', self.size, color=color)
def get_image (self): def get_image (self):
self.__finish_image__() self.__finish_image__()
return self.__image__ return self.__image__
def draw (self, subimage, pos): def draw (self, subimage, pos, mask=False):
self.__image__.paste(subimage, pos) img_mask = None
if mask:
def draw_bitmap (self, subimage, pos): img_mask = ImageOps.invert(subimage.convert('L'))
ImageDraw.Draw(self.__image__).bitmap(pos, subimage) self.__image__.paste(subimage, pos, mask=img_mask)
def draw_design (self, entity): def draw_design (self, entity):
if entity.is_bitmap: self.draw(entity.get_image(), entity.pos, entity.mask)
self.draw_bitmap(entity.get_image(), entity.pos)
else:
self.draw(entity.get_image(), entity.pos)
def draw_image (self, path, pos): def draw_image (self, path, pos):
self.draw(Image.open(path), pos) self.draw(Image.open(path), pos)

View file

@ -109,7 +109,7 @@ class MonthOvPanel (PanelDesign):
def __get_today_box_pos__ (self): def __get_today_box_pos__ (self):
x, y = self.__get_day_pos__(int(datetime.now().day / 7), datetime.now().weekday()) x, y = self.__get_day_pos__(int(datetime.now().day / 7), datetime.now().weekday())
return (x, y + (self.__abs_pos__(daynumberboxsize)[1] - self.__abs_pos__(dayhighlightboxsize)[1]) / 2) return (x, int(y + (self.__abs_pos__(daynumberboxsize)[1] - self.__abs_pos__(dayhighlightboxsize)[1]) / 2))
def __draw_highlight_box__ (self, size, pos, color='black', width=1): def __draw_highlight_box__ (self, size, pos, color='black', width=1):
design = BoxDesign(size, outline=color, width = width) design = BoxDesign(size, outline=color, width = width)

View file

@ -8,20 +8,18 @@ class TextDesign (DesignEntity):
"""Object that manages all information relevant to text """Object that manages all information relevant to text
and prints it to an image""" and prints it to an image"""
def __init__ (self, size, font = "Assistant-Regular.ttf", fontsize = 12, text = "", horizontalalignment = "left", verticalalignment = "top"): def __init__ (self, size, font = "Assistant-Regular.ttf", fontsize = 12, text = "", horizontalalignment = "left", verticalalignment = "top"):
super(TextDesign, self).__init__(size) super(TextDesign, self).__init__(size, mask = True)
self.font_family = font self.font_family = font
self.font_size = fontsize self.font_size = fontsize
self.text = text self.text = text
self.horizontal_alignment = horizontalalignment self.horizontal_alignment = horizontalalignment
self.vertical_alignment = verticalalignment self.vertical_alignment = verticalalignment
self.is_bitmap = True
def __finish_image__ (self): def __finish_image__ (self):
self.__init_image__() self.__init_image__()
self.__font__ = ImageFont.truetype(path + self.font_family, self.font_size) self.__font__ = ImageFont.truetype(path + self.font_family, self.font_size)
pos = self.__pos_from_alignment__() pos = self.__pos_from_alignment__()
ImageDraw.Draw(self.__image__).text(pos, self.text, fill=0, font=self.__font__) ImageDraw.Draw(self.__image__).text(pos, self.text, fill=0, font=self.__font__)
self.__image__ = ImageOps.invert(self.__image__)
def __pos_from_alignment__ (self): def __pos_from_alignment__ (self):
width, height = self.__font__.getsize(self.text) width, height = self.__font__.getsize(self.text)