当前位置: 首页>>代码示例>>Python>>正文


Python PIL.ImageFont方法代码示例

本文整理汇总了Python中PIL.ImageFont方法的典型用法代码示例。如果您正苦于以下问题:Python PIL.ImageFont方法的具体用法?Python PIL.ImageFont怎么用?Python PIL.ImageFont使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PIL的用法示例。


在下文中一共展示了PIL.ImageFont方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: generate_ascii

# 需要导入模块: import PIL [as 别名]
# 或者: from PIL import ImageFont [as 别名]
def generate_ascii(self, image):
		font = PIL.ImageFont.truetype(self.files_path('FreeMonoBold.ttf'), 15, encoding="unic")
		image_width, image_height = image.size
		aalib_screen_width= int(image_width/24.9)*10
		aalib_screen_height= int(image_height/41.39)*10
		screen = aalib.AsciiScreen(width=aalib_screen_width, height=aalib_screen_height)
		im = image.convert("L").resize(screen.virtual_size)
		screen.put_image((0,0), im)
		y = 0
		how_many_rows = len(screen.render().splitlines()) 
		new_img_width, font_size = font.getsize(screen.render().splitlines()[0])
		img = PIL.Image.new("RGBA", (new_img_width, how_many_rows*15), (255,255,255))
		draw = PIL.ImageDraw.Draw(img)
		for lines in screen.render().splitlines():
			draw.text((0,y), lines, (0,0,0), font=font)
			y = y + 15
		imagefit = PIL.ImageOps.fit(img, (image_width, image_height), PIL.Image.ANTIALIAS)
		return imagefit 
开发者ID:NotSoSuper,项目名称:NotSoBot,代码行数:20,代码来源:Fun.py

示例2: __init__

# 需要导入模块: import PIL [as 别名]
# 或者: from PIL import ImageFont [as 别名]
def __init__(self, height: int, width: int, icon_font: ImageFont,
                 text_font: ImageFont, icon_lookup: WeatherIconLookup) -> None:
        super().__init__(height, width)

        self.weather_icon = TextWidget(height // 2, width, font=icon_font)
        self.weather_icon.row = 0
        self.weather_icon.col = 0
        self.weather_icon.text = icon_lookup.look_up_with_name('wi-na')
        self.add_child(self.weather_icon)

        self.high_temp_text = TextWidget(height // 4, width, font=text_font)
        self.high_temp_text.row = height // 2
        self.high_temp_text.col = 0
        self.high_temp_text.text = '--'
        self.add_child(self.high_temp_text)

        self.low_temp_text = TextWidget(height // 4, width, font=text_font)
        self.low_temp_text.row = height // 4 * 3
        self.low_temp_text.col = 0
        self.low_temp_text.text = '--'
        self.add_child(self.low_temp_text)

        self.icon_lookup = icon_lookup 
开发者ID:zli117,项目名称:EInk-Calendar,代码行数:25,代码来源:weather.py

示例3: __init__

# 需要导入模块: import PIL [as 别名]
# 或者: from PIL import ImageFont [as 别名]
def __init__(self, height: int, width: int, header_font: ImageFont,
                 event_font: ImageFont) -> None:
        super().__init__(height, width)
        header = TextWidget(height // 10, width, font=header_font)
        header.row = 0
        header.col = 0
        header.text = 'Events'
        header.foreground = self.background
        header.background = self.foreground
        header.is_draw_border(True)
        self.add_child(header)

        event_top = height // 5
        self.event_widgets = []
        while event_top < self.width:
            event = EventWidget(height // 10, width, event_font=event_font)
            event.row = event_top
            event.col = 0
            self.event_widgets.append(event)
            self.add_child(event)
            event_top += height // 10 
开发者ID:zli117,项目名称:EInk-Calendar,代码行数:23,代码来源:event.py

示例4: __init__

# 需要导入模块: import PIL [as 别名]
# 或者: from PIL import ImageFont [as 别名]
def __init__(self):
        global PIL
        import PIL, PIL.Image, PIL.ImageDraw, PIL.ImageTk, PIL.ImageFont
        self.upscaled = False
        self.sysfontfolders = dict([("windows","C:/Windows/Fonts/"),
                                    ("darwin", "/Library/Fonts/"),
                                    ("linux", "/usr/share/fonts/truetype/") ])
        self.fontfilenames = dict([("default", "TIMES.TTF"),
                                   ("times new roman","TIMES.TTF"),
                                   ("arial","ARIAL.TTF")]) 
开发者ID:karimbahgat,项目名称:GeoVis,代码行数:12,代码来源:__init__.py

示例5: _BasicText

# 需要导入模块: import PIL [as 别名]
# 或者: from PIL import ImageFont [as 别名]
def _BasicText(self, relx, rely, text, options):
        """
draws basic text, no effects
"""
        fontlocation = self.sysfontfolders[OSSYSTEM]+self.fontfilenames[options["textfont"]]
        font = PIL.ImageFont.truetype(fontlocation, size=options["textsize"])
        fontwidth, fontheight = self.drawer.textsize(text, font)
        textanchor = options.get("textanchor")
        if textanchor:
            textanchor = textanchor.lower()
            if textanchor == "center":
                x = int(MAPWIDTH*relx) - int(fontwidth/2.0)
                y = int(MAPHEIGHT*rely) - int(fontheight/2.0)
            else:
                x = int(MAPWIDTH*relx) - int(fontwidth/2.0)
                y = int(MAPHEIGHT*rely) - int(fontheight/2.0)
                if "n" in textanchor:
                    y = int(MAPHEIGHT*rely)
                elif "s" in textanchor:
                    y = int(MAPHEIGHT*rely) - int(fontheight)
                if "e" in textanchor:
                    x = int(MAPWIDTH*relx) - int(fontwidth)
                elif "w" in textanchor:
                    x = int(MAPWIDTH*relx)
        if options.get("textboxfillcolor") or options.get("textboxoutlinecolor"):
            relfontwidth, relfontheight = (fontwidth/float(MAPWIDTH), fontheight/float(MAPHEIGHT))
            relxmid,relymid = (x/float(MAPWIDTH)+relfontwidth/2.0,y/float(MAPHEIGHT)+relfontheight/2.0)
            relupperleft = (relxmid-relfontwidth*options["textboxfillsize"]/2.0, relymid-relfontheight*options["textboxfillsize"]/2.0)
            relbottomright = (relxmid+relfontwidth*options["textboxfillsize"]/2.0, relymid+relfontheight*options["textboxfillsize"]/2.0)
            options["fillcolor"] = options["textboxfillcolor"]
            options["outlinecolor"] = options["textboxoutlinecolor"]
            options["outlinewidth"] = options["textboxoutlinewidth"]
            self.RenderRectangle(relupperleft, relbottomright, options)
        self.drawer.text((x,y), text=text, font=font, fill=options["textcolor"]) 
开发者ID:karimbahgat,项目名称:GeoVis,代码行数:36,代码来源:__init__.py

示例6: __init__

# 需要导入模块: import PIL [as 别名]
# 或者: from PIL import ImageFont [as 别名]
def __init__(self, font:ImageFont):
        self.font = font
        self.tokens = list() 
开发者ID:rabbitism,项目名称:GadioVideo,代码行数:5,代码来源:wrapper.py

示例7: __init__

# 需要导入模块: import PIL [as 别名]
# 或者: from PIL import ImageFont [as 别名]
def __init__(self,
                 height: int,
                 width: int,
                 font: ImageFont = None) -> None:
        super().__init__(height, width)
        self._text = ''
        self._font = font
        self._vertical_align = Alignments.CENTER
        self._horizontal_align = Alignments.CENTER 
开发者ID:zli117,项目名称:EInk-Calendar,代码行数:11,代码来源:text.py

示例8: read_font

# 需要导入模块: import PIL [as 别名]
# 或者: from PIL import ImageFont [as 别名]
def read_font(fn):
    font = PIL.ImageFont.truetype(fn, min(w0, h0))

    # We need to make sure we scale down the fonts but preserve the vertical alignment
    min_ly = float('inf')
    max_hy = float('-inf')
    max_width = 0
    imgs = []

    for char in chars:
        print '...', char
        # Draw character
        img = PIL.Image.new("L", (w0*5, h0*3), 255)
        draw = PIL.ImageDraw.Draw(img)
        draw.text((w0, h0), char, font=font)

        # Get bounding box
        diff = PIL.ImageChops.difference(img, blank)
        lx, ly, hx, hy = diff.getbbox()
        min_ly = min(min_ly, ly)
        max_hy = max(max_hy, hy)
        max_width = max(max_width, hx - lx)
        imgs.append((lx, hx, img))

    print 'crop dims:', max_hy - min_ly, max_width
    scale_factor = min(1.0 * h / (max_hy - min_ly), 1.0 * w / max_width)
    data = []

    for lx, hx, img in imgs:
        img = img.crop((lx, min_ly, hx, max_hy))

        # Resize to smaller
        new_width = (hx-lx) * scale_factor
        new_height = (max_hy - min_ly) * scale_factor
        img = img.resize((int(new_width), int(new_height)), PIL.Image.ANTIALIAS)

        # Expand to square
        img_sq = PIL.Image.new('L', (w, h), 255)
        offset_x = (w - new_width)/2
        offset_y = (h - new_height)/2
        print offset_x, offset_y
        img_sq.paste(img, (int(offset_x), int(offset_y)))

        # Convert to numpy array
        matrix = numpy.array(img_sq.getdata()).reshape((h, w))
        matrix = 255 - matrix
        data.append(matrix)

    return numpy.array(data) 
开发者ID:erikbern,项目名称:deep-fonts,代码行数:51,代码来源:create_dataset.py


注:本文中的PIL.ImageFont方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。