python类add()的实例源码

pildriver.py 文件源码 项目:ascii-art-py 作者: blinglnav 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def do_add(self):
        """usage: add <image:pic1> <image:pic2> <int:offset> <float:scale>

        Pop the two top images, produce the scaled sum with offset.
        """
        from PIL import ImageChops
        image1 = self.do_pop()
        image2 = self.do_pop()
        scale = float(self.do_pop())
        offset = int(self.do_pop())
        self.push(ImageChops.add(image1, image2, scale, offset))
extract_seal.py 文件源码 项目:indus-script-ocr 作者: tpsatish95 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def trim(im):

    bg = Image.new(im.mode, im.size, im.getpixel((0, 0)))
    diff = ImageChops.difference(im, bg)
    diff = ImageChops.add(diff, diff, 2.0, -100)
    bbox = diff.getbbox()
    if bbox:
        return im.crop(bbox)
webcap_server.py 文件源码 项目:plumeria 作者: sk89q 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def trim(im):
    bg = Image.new(im.mode, im.size, im.getpixel((0, 0)))
    diff = ImageChops.difference(im, bg)
    diff = ImageChops.add(diff, diff, 2.0, -100)
    bbox = diff.getbbox()
    if bbox:
        return im.crop(bbox)
    else:
        return im
webcap_server.py 文件源码 项目:plumeria 作者: sk89q 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def setup():
    config.add(api_key)
    config.add(page_load_timeout)

    if not api_key():
        raise PluginSetupError("This plugin requires an API key to be chosen.")

    app.add(handle)
graph.py 文件源码 项目:plumeria 作者: sk89q 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def trim_whitespace(im):
    bg = Image.new(im.mode, im.size, im.getpixel((0, 0)))
    diff = ImageChops.difference(im, bg)
    diff = ImageChops.add(diff, diff, 2.0, -100)
    bbox = diff.getbbox()
    if bbox:
        return im.crop(bbox)
graph.py 文件源码 项目:plumeria 作者: sk89q 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def setup():
    commands.add(pie)
    commands.add(bar)
    commands.add(histogram)
    commands.add(latex)
trayicon.py 文件源码 项目:bittray 作者: nkuttler 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def trim(self, im):
        """
        Auto-trim
        """
        bg = Image.new(im.mode, im.size, im.getpixel((0, 0)))
        diff = ImageChops.difference(im, bg)
        diff = ImageChops.add(diff, diff, 2.0, -100)
        bbox = diff.getbbox()
        if bbox:
            return im.crop(bbox)
screenshot.py 文件源码 项目:netstalking-telegram-bot 作者: pantyusha 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def trim(im):
    pixel = (255, 255, 255)  # ????????????? ?? ????? ????
    # pixel = im.getpixel((0,0))  # ????????????? ?? ??????? ? ?????? ???????? ????
    bg = Image.new(im.mode, im.size, pixel)
    diff = ImageChops.difference(im, bg)
    diff = ImageChops.add(diff, diff, 2.0, -100)
    bbox = diff.getbbox()
    logger.info(bbox)
    if bbox:
        return im.crop(bbox)
    else:
        return im
graph.py 文件源码 项目:plumeria 作者: sk89q 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def pie(message):
    """
    Generate a pie graph. To specify the parts of the pie, make a
    list separated by new lines, semi-colons or commas where each
    list entry has a percentage in it (if there is more than one, the
    first percentage is used).

    To specify a graph title, don't provide a percentage for one of the
    list items.

    Example::

        /pie Materials, 40% Glass, 22%

    The percentages do not need to add up to 100%. If they do not, then
    the percentage values will be normalized so that they do add up to 100%.

    """
    title, labels, data = extract_data(message.content, pattern=PERCENTAGE_PATTERN, normalize=True)

    def execute():
        with lock:
            plt.figure(1, figsize=(5, 5))
            ax = plt.axes([0.1, 0.1, 0.4, 0.4])

            plt.pie(data, labels=labels, autopct='%1.0f%%', startangle=90)

            if title:
                plt.title(title)

            prop = fm.FontProperties(fname=font_path, size=11)
            for text in ax.texts:
                text.set_fontproperties(prop)

            buf = io.BytesIO()
            plt.savefig(buf, bbox_inches='tight', transparent=False, pad_inches=0.1)

            plt.clf()
        return buf

    buf = await asyncio.get_event_loop().run_in_executor(None, execute)

    return Response("", attachments=[MemoryAttachment(buf, "graph.png", "image/png")])


问题


面经


文章

微信
公众号

扫码关注公众号