Beispiel #1
0
 def textimg(text,
             font,
             size=None,
             fill=None,
             padding=0,
             mode='RGBA',
             bg=None,
             storage=default_storage):
     font = get_font_object(font, size)
     text = smart_text(text)
     imgsize, offset = ImageQuery.img_textbox(text, font, size)
     if bg is None:
         bg = [0, 0, 0, 0]
         # Workaround: Image perhaps is converted to RGB before pasting,
         # black background draws dark outline around text
         if fill:
             for i in xrange(0, min(len(fill), 3)):
                 bg[i] = fill[i]
     if padding:
         imgsize = (imgsize[0] + padding * 2, imgsize[1] + padding * 2)
         offset = (offset[0] + padding, offset[1] + padding)
     fontimage = Image.new(mode, imgsize, tuple(bg))
     draw = ImageDraw.Draw(fontimage)
     draw.text(offset, text, font=font, fill=fill)
     return RawImageQuery(fontimage, storage=storage)
 def execute(self, image, query):
     from imagequery import ImageQuery # late import to avoid circular import
     image = image.copy()
     font = get_font_object(self.font, self.size)
     size, offset = ImageQuery.img_textbox(self.text, self.font, self.size)
     x = get_coords(image.size[0], size[0], self.x) + offset[0]
     y = get_coords(image.size[1], size[1], self.y) + offset[1]
     draw = ImageDraw.Draw(image)
     text = smart_unicode(self.text)
     draw.text((x, y), text, font=font, fill=self.fill)
     return image
Beispiel #3
0
    def execute(self, image, query):
        from imagequery import ImageQuery  # late import to avoid circular import

        image = image.copy()
        font = get_font_object(self.font, self.size)
        size, offset = ImageQuery.img_textbox(self.text, self.font, self.size)
        x = get_coords(image.size[0], size[0], self.x) + offset[0]
        y = get_coords(image.size[1], size[1], self.y) + offset[1]
        draw = ImageDraw.Draw(image)
        text = smart_text(self.text)
        draw.text((x, y), text, font=font, fill=self.fill)
        return image
Beispiel #4
0
 def img_textbox(text, font, size=None):
     font = get_font_object(font, size)
     text = smart_text(text)
     try:
         imgsize, offset = font.font.getsize(text)
         if isinstance(imgsize, int) and isinstance(offset, int):
             imgsize = (imgsize, offset)
             offset = (0, 0)
     except AttributeError:
         imgsize = font.getsize(text)
         offset = (0, 0)
     return (
         imgsize[0] - offset[0],
         imgsize[1] - offset[1],
     ), (
         -offset[0],
         -offset[1],
     )
Beispiel #5
0
 def textimg(text, font, size=None, fill=None, padding=0, mode='RGBA', bg=None, storage=default_storage):
     font = get_font_object(font, size)
     text = smart_unicode(text)
     imgsize, offset = ImageQuery.img_textbox(text, font, size)
     if bg is None:
         bg = [0,0,0,0]
         # Workaround: Image perhaps is converted to RGB before pasting,
         # black background draws dark outline around text
         if fill:
             for i in xrange(0, min(len(fill), 3)):
                 bg[i] = fill[i]
     if padding:
         imgsize = (imgsize[0] + padding * 2, imgsize[1] + padding * 2)
         offset = (offset[0] + padding, offset[1] + padding)
     fontimage = Image.new(mode, imgsize, tuple(bg))
     draw = ImageDraw.Draw(fontimage)
     draw.text(offset, text, font=font, fill=fill)
     return RawImageQuery(fontimage, storage=storage)
Beispiel #6
0
 def img_textbox(text, font, size=None):
     font = get_font_object(font, size)
     text = smart_unicode(text)
     try:
         imgsize, offset = font.font.getsize(text)
         if isinstance(imgsize, int) and isinstance(offset, int):
             imgsize = (imgsize, offset)
             offset = (0, 0)
     except AttributeError:
         imgsize = font.getsize(text)
         offset = (0, 0)
     return (
         imgsize[0] - offset[0],
         imgsize[1] - offset[1],
     ), (
         -offset[0],
         -offset[1],
     )
Beispiel #7
0
 def textbox(text, font, size=None):
     font = get_font_object(font, size)
     text = smart_text(text)
     return font.getsize(text)
Beispiel #8
0
 def execute(self, image, query):
     font = get_font_object(self.font, self.size)
     font.getmask(self.text)
 def execute(self, image, query):
     font = get_font_object(self.font, self.size)
     font.getmask(self.text)
Beispiel #10
0
 def textbox(text, font, size=None):
     font = get_font_object(font, size)
     text = smart_unicode(text)
     return font.getsize(text)