cbcreator/cbcreator.py
def save(self, output):
        if self.titlefont is None:
            fontfile = "fonts/{:03}.ttf".format(randint(1, 4))
            fontfile = getrc(fontfile)
            self.titlefont = ImageFont.truetype(
                fontfile, self.titlesize, encoding="unic")
        """ Save the slide to a file. """
        if self.textfont is None:
            fontfile = "fonts/{:03}.ttf".format(randint(1, 4))
            fontfile = getrc(fontfile)
            self.textfont = ImageFont.truetype(
                fontfile, self.textsize, encoding="unic")
        # Only create the ImageDraw object if we aren't just resizing
        if self.title or self.text or self.pics:
            draw = ImageDraw.Draw(self.im)
            if not self.title:
                self.title = ""
            # size tuple of the title
            sizet = draw.textsize(self.title, font=self.titlefont)
            onechar = draw.textsize("a", font=self.textfont)[0]
            # don't ask what the 3 is, it just works
            self.text = autowrap(self.text, 2661 - 3 *
                                 onechar, draw, self.textfont)
            sizex = draw.textsize(self.text, font=self.textfont)
            leftt = (2661 - sizet[0]) // 2
            # Set margin to the width of a character
            leftx = (2661 - sizex[0]) // 2
            top = (3072 - sizet[1] - sizex[1] - onechar) // 2
            draw.text((leftt, top), self.title,
                      font=self.titlefont, fill=self.titlecolor)
            draw.text((leftx, top + sizet[1] + onechar),
                      self.text, font=self.textfont, fill=self.textcolor)
            # # TODO: Render the slide to self.im
            # # Use https://pillow.readthedocs.io/en/stable/reference/
            # # Image.html?highlight=overlay#PIL.Image.Image.alpha_composite
        self.im.save(output)
 Save the slide to a file. 
Save the slide to a file.
Save the slide to a file .
def save(self, output):
        if self.titlefont is None:
            fontfile = "fonts/{:03}.ttf".format(randint(1, 4))
            fontfile = getrc(fontfile)
            self.titlefont = ImageFont.truetype(
                fontfile, self.titlesize, encoding="unic")
        if self.textfont is None:
            fontfile = "fonts/{:03}.ttf".format(randint(1, 4))
            fontfile = getrc(fontfile)
            self.textfont = ImageFont.truetype(
                fontfile, self.textsize, encoding="unic")
        if self.title or self.text or self.pics:
            draw = ImageDraw.Draw(self.im)
            if not self.title:
                self.title = ""
            sizet = draw.textsize(self.title, font=self.titlefont)
            onechar = draw.textsize("a", font=self.textfont)[0]
            self.text = autowrap(self.text, 2661 - 3 *
                                 onechar, draw, self.textfont)
            sizex = draw.textsize(self.text, font=self.textfont)
            leftt = (2661 - sizet[0]) // 2
            leftx = (2661 - sizex[0]) // 2
            top = (3072 - sizet[1] - sizex[1] - onechar) // 2
            draw.text((leftt, top), self.title,
                      font=self.titlefont, fill=self.titlecolor)
            draw.text((leftx, top + sizet[1] + onechar),
                      self.text, font=self.textfont, fill=self.textcolor)
        self.im.save(output)
def save ( self , output ) : if self . titlefont is None : fontfile = "fonts/{:03}.ttf" . format ( randint ( 1 , 4 ) ) fontfile = getrc ( fontfile ) self . titlefont = ImageFont . truetype ( fontfile , self . titlesize , encoding = "unic" ) if self . textfont is None : fontfile = "fonts/{:03}.ttf" . format ( randint ( 1 , 4 ) ) fontfile = getrc ( fontfile ) self . textfont = ImageFont . truetype ( fontfile , self . textsize , encoding = "unic" ) if self . title or self . text or self . pics : draw = ImageDraw . Draw ( self . im ) if not self . title : self . title = "" sizet = draw . textsize ( self . title , font = self . titlefont ) onechar = draw . textsize ( "a" , font = self . textfont ) [ 0 ] self . text = autowrap ( self . text , 2661 - 3 * onechar , draw , self . textfont ) sizex = draw . textsize ( self . text , font = self . textfont ) leftt = ( 2661 - sizet [ 0 ] ) // 2 leftx = ( 2661 - sizex [ 0 ] ) // 2 top = ( 3072 - sizet [ 1 ] - sizex [ 1 ] - onechar ) // 2 draw . text ( ( leftt , top ) , self . title , font = self . titlefont , fill = self . titlecolor ) draw . text ( ( leftx , top + sizet [ 1 ] + onechar ) , self . text , font = self . textfont , fill = self . textcolor ) self . im . save ( output )
Save the slide to a file.
Save the slide to a file .
""" Save the slide to a file. """ # Only create the ImageDraw object if we aren't just resizing # size tuple of the title # don't ask what the 3 is, it just works # Set margin to the width of a character # # TODO: Render the slide to self.im # # Use https://pillow.readthedocs.io/en/stable/reference/ # # Image.html?highlight=overlay#PIL.Image.Image.alpha_composite
self
output