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


Python color.Color方法代码示例

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


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

示例1: save_image

# 需要导入模块: from wand import color [as 别名]
# 或者: from wand.color import Color [as 别名]
def save_image(pdf_path, img_path, page_num):
    """

    Creates images for a page of the input pdf document and saves it
    at img_path.

    :param pdf_path: path to pdf to create images for.
    :param img_path: path where to save the images.
    :param page_num: page number to create image from in the pdf file.
    :return:
    """
    pdf_img = Image(filename="{}[{}]".format(pdf_path, page_num))
    with pdf_img.convert("png") as converted:
        # Set white background.
        converted.background_color = Color("white")
        converted.alpha_channel = "remove"
        converted.save(filename=img_path) 
开发者ID:HazyResearch,项目名称:pdftotree,代码行数:19,代码来源:visual_utils.py

示例2: display_bounding_boxes

# 需要导入模块: from wand import color [as 别名]
# 或者: from wand.color import Color [as 别名]
def display_bounding_boxes(self, page_num, bboxes, alternate_colors=True):
        elems = self.elems[page_num]
        page_width, page_height = int(elems.layout.width), int(elems.layout.height)
        img = pdf_to_img(self.pdf_file, page_num, page_width, page_height)
        draw = Drawing()
        draw.fill_color = Color("rgba(0, 0, 0, 0)")
        color = Color("blue")
        draw.stroke_color = color
        for block in bboxes:
            top, left, bottom, right = block[-4:]
            draw.stroke_color = Color(
                "rgba({},{},{}, 1)".format(
                    str(np.random.randint(255)),
                    str(np.random.randint(255)),
                    str(np.random.randint(255)),
                )
            )
            draw.rectangle(
                left=float(left),
                top=float(top),
                right=float(right),
                bottom=float(bottom),
            )
        draw(img)
        return img 
开发者ID:HazyResearch,项目名称:pdftotree,代码行数:27,代码来源:TableExtractML.py

示例3: display_bounding_boxes

# 需要导入模块: from wand import color [as 别名]
# 或者: from wand.color import Color [as 别名]
def display_bounding_boxes(img, blocks, alternatecolors=False, color=Color("blue")):
    """
    Displays each of the bounding boxes passed in 'boxes' on an image of the pdf
    pointed to by pdf_file
    boxes is a list of 5-tuples (page, top, left, bottom, right)
    """
    draw = Drawing()
    draw.fill_color = Color("rgba(0, 0, 0, 0)")
    draw.stroke_color = color
    for block in blocks:
        top, left, bottom, right = block[-4:]
        if alternatecolors:
            draw.stroke_color = Color(
                "rgba({},{},{}, 1)".format(
                    str(np.random.randint(255)),
                    str(np.random.randint(255)),
                    str(np.random.randint(255)),
                )
            )
        draw.rectangle(
            left=float(left), top=float(top), right=float(right), bottom=float(bottom)
        )
        draw(img)
    display(img) 
开发者ID:HazyResearch,项目名称:pdftotree,代码行数:26,代码来源:display_utils.py

示例4: _run_convert

# 需要导入模块: from wand import color [as 别名]
# 或者: from wand.color import Color [as 别名]
def _run_convert(filename, page, res=120):
    idx = page + 1
    temp_time = time.time() * 1000
    # 由于每次转换的时候都需要重新将整个PDF载入内存,所以这里使用内存缓存
    pdfile = getPdfReader(filename)
    pageObj = pdfile.getPage(page)
    dst_pdf = PdfFileWriter()
    dst_pdf.addPage(pageObj)

    pdf_bytes = io.BytesIO()
    dst_pdf.write(pdf_bytes)
    pdf_bytes.seek(0)

    img = Image(file=pdf_bytes, resolution=res)
    img.format = 'png'
    img.compression_quality = 90
    img.background_color = Color("white")
    # 保存图片
    img_path = '%s%d.png' % (filename[:filename.rindex('.')], idx)
    img.save(filename=img_path)
    img.destroy()
    img = None
    pdf_bytes = None
    dst_pdf = None
    print('convert page %d cost time %d' % (idx, (time.time() * 1000 - temp_time))) 
开发者ID:cnych,项目名称:pdf2images,代码行数:27,代码来源:app.py

示例5: render_chart

# 需要导入模块: from wand import color [as 别名]
# 或者: from wand.color import Color [as 别名]
def render_chart(pdf_file, page, bounds, dpi, target):
    """Renders part of a pdf file with imagemagick.
    Pass this function the bounds and resolution.
    """

    pdf_page = pdf_file + '[{}]'.format(page)
    with Image(filename=pdf_page, resolution=dpi) as img:
        factor = 1.0*dpi/100

        x0 = bounds[0]
        y0 = bounds[1]
        w = bounds[2] - x0
        h = bounds[3] - y0

        img.crop(left=int(x0*factor), top=int(y0*factor),
                 width=int(w*factor), height=int(h*factor))

        # put transparent image on white background
        with Image(width=img.width, height=img.height,
                   background=Color("white")) as bg:
            bg.composite(img, 0, 0)
            bg.save(filename=target) 
开发者ID:domoritz,项目名称:label_generator,代码行数:24,代码来源:render.py

示例6: setup

# 需要导入模块: from wand import color [as 别名]
# 或者: from wand.color import Color [as 别名]
def setup(bot):
    global geotiler
    global Color, Drawing, display, Image, Color, Image, COMPOSITE_OPERATORS
    global BeautifulSoup
    
    check_folders()
    check_files()
    try:
        import geotiler
    except:
        raise ModuleNotFound("geotiler is not installed. Do 'pip3 install geotiler --upgrade' to use this cog.")
    try:
        from bs4 import BeautifulSoup
    except:
        raise ModuleNotFound("BeautifulSoup is not installed. Do 'pip3 install BeautifulSoup --upgrade' to use this cog.")        
    try: 
        from wand.image import Image, COMPOSITE_OPERATORS
        from wand.drawing import Drawing
        from wand.display import display
        from wand.image import Image
        from wand.color import Color
    except:
        raise ModuleNotFound("Wand is not installed. Do 'pip3 install Wand --upgrade' and make sure you have ImageMagick installed http://docs.wand-py.org/en/0.4.2/guide/install.html")    
    bot.add_cog(OpenStreetMaps(bot)) 
开发者ID:Fr6jDJF,项目名称:Mash-Cogs,代码行数:26,代码来源:omaps.py

示例7: display_bounding_boxes_within_notebook

# 需要导入模块: from wand import color [as 别名]
# 或者: from wand.color import Color [as 别名]
def display_bounding_boxes_within_notebook(
    page_num, extractor, blocks, alternatecolors=False, color=Color("blue")
):
    """
    Displays each of the bounding boxes passed in 'boxes' on an image of the pdf
    pointed to by pdf_file
    boxes is a list of 5-tuples (page, top, left, bottom, right)
    """
    elems = extractor.elems[page_num]
    page_width, page_height = int(elems.layout.width), int(elems.layout.height)
    img = pdf_to_img(extractor.pdf_file, page_num, page_width, page_height)
    draw = Drawing()
    draw.fill_color = Color("rgba(0, 0, 0, 0)")
    draw.stroke_color = color
    for block in blocks:
        top, left, bottom, right = block[-4:]
        if alternatecolors:
            draw.stroke_color = Color(
                "rgba({},{},{}, 1)".format(
                    str(np.random.randint(255)),
                    str(np.random.randint(255)),
                    str(np.random.randint(255)),
                )
            )
        draw.rectangle(
            left=float(left), top=float(top), right=float(right), bottom=float(bottom)
        )
        draw(img)
    return img 
开发者ID:HazyResearch,项目名称:pdftotree,代码行数:31,代码来源:display_utils.py

示例8: display_boxes

# 需要导入模块: from wand import color [as 别名]
# 或者: from wand.color import Color [as 别名]
def display_boxes(self, tree, html_path, filename_prefix, alternate_colors=False):
        """
        Displays each of the bounding boxes passed in 'boxes' on images of the pdf
        pointed to by pdf_file
        boxes is a list of 5-tuples (page, top, left, bottom, right)
        """
        imgs = []
        colors = {
            "section_header": Color("blue"),
            "figure": Color("green"),
            "figure_caption": Color("green"),
            "table_caption": Color("red"),
            "list": Color("yellow"),
            "paragraph": Color("gray"),
            "table": Color("red"),
            "header": Color("brown"),
        }
        for i, page_num in enumerate(tree.keys()):
            img = self.pdf_to_img(page_num)
            draw = Drawing()
            draw.fill_color = Color("rgba(0, 0, 0, 0.0)")
            for clust in tree[page_num]:
                for (pnum, pwidth, pheight, top, left, bottom, right) in tree[page_num][
                    clust
                ]:
                    draw.stroke_color = colors[clust]
                    draw.rectangle(left=left, top=top, right=right, bottom=bottom)
                    draw.push()
                    draw.font_size = 20
                    draw.font_weight = 10
                    draw.fill_color = colors[clust]
                    if int(left) > 0 and int(top) > 0:
                        draw.text(x=int(left), y=int(top), body=clust)
                    draw.pop()
            draw(img)
            img.save(filename=html_path + filename_prefix + "_page_" + str(i) + ".png")
            imgs.append(img)
        return imgs 
开发者ID:HazyResearch,项目名称:pdftotree,代码行数:40,代码来源:TreeVisualizer.py

示例9: display_boxes

# 需要导入模块: from wand import color [as 别名]
# 或者: from wand.color import Color [as 别名]
def display_boxes(
        self, pdf_file: str, boxes: List[Bbox], alternate_colors: bool = False,
    ) -> List[Image]:
        """Display bounding boxes on the document.

        Display each of the bounding boxes passed in 'boxes' on images of the pdf
        pointed to by pdf_file
        boxes is a list of 5-tuples (page, top, left, bottom, right)
        """
        imgs = []
        with Color("blue") as blue, Color("red") as red, Color(
            "rgba(0, 0, 0, 0.0)"
        ) as transparent, Drawing() as draw:
            colors = [blue, red]
            boxes_per_page: DefaultDict[int, int] = defaultdict(int)
            boxes_by_page: DefaultDict[
                int, List[Tuple[int, int, int, int]]
            ] = defaultdict(list)
            for i, (page, top, bottom, left, right) in enumerate(boxes):
                boxes_per_page[page] += 1
                boxes_by_page[page].append((top, bottom, left, right))
            for i, page_num in enumerate(boxes_per_page.keys()):
                img = pdf_to_img(pdf_file, page_num)
                draw.fill_color = transparent
                for j, (top, bottom, left, right) in enumerate(boxes_by_page[page_num]):
                    draw.stroke_color = colors[j % 2] if alternate_colors else colors[0]
                    draw.rectangle(left=left, top=top, right=right, bottom=bottom)
                draw(img)
                imgs.append(img)
            return imgs 
开发者ID:HazyResearch,项目名称:fonduer,代码行数:32,代码来源:visualizer.py

示例10: save_as_image

# 需要导入模块: from wand import color [as 别名]
# 或者: from wand.color import Color [as 别名]
def save_as_image(document, save_as, constants):
    from wand.image import Image
    from wand.color import Color
    from wand.exceptions import DelegateError

    temp_directory = pathlib.Path(tempfile.mkdtemp())

    temp_pdf_name = temp_directory / (save_as.name + '.pdf')

    document.SaveAs2(
        FileName=str(temp_pdf_name.absolute()),
        FileFormat=constants.wdFormatPDF,
    )

    try:
        with Image(filename=str(temp_pdf_name), resolution=300) as pdf:
            pdf.trim()

            with Image(width=pdf.width, height=pdf.height, background=Color('white')) as png:
                png.composite(pdf, 0, 0)
                png.save(filename=str(save_as))
    except DelegateError:
        print('Error: You may need to install ghostscript as well', file=sys.stderr)
        exit(1)

# https://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.wdsaveformat.aspx 
开发者ID:orf,项目名称:wordinserter,代码行数:28,代码来源:cli.py

示例11: svg_to_png

# 需要导入模块: from wand import color [as 别名]
# 或者: from wand.color import Color [as 别名]
def svg_to_png(infile, outfile, dpi=300):
    with Image(resolution=300) as image:
        with Color('transparent') as background_color:
            library.MagickSetBackgroundColor(image.wand,
                                            background_color.resource)
        image.read(filename=infile, resolution=300)
        png_image = image.make_blob("png32")
        with open(outfile, "wb") as out:
            out.write(png_image) 
开发者ID:yaqwsx,项目名称:PcbDraw,代码行数:11,代码来源:pcbdraw.py

示例12: pdf2png

# 需要导入模块: from wand import color [as 别名]
# 或者: from wand.color import Color [as 别名]
def pdf2png(filename):
    from wand.image import Image
    from wand.color import Color
    import os
    with Image(filename="{}.pdf".format(filename), resolution=500) as img:
        with Image(
                width=img.width, height=img.height,
                background=Color("white")) as bg:
            bg.composite(img, 0, 0)
            bg.save(filename="{}.png".format(filename))
    os.remove('{}.pdf'.format(filename))


# ==================================================================#
# ==================================================================# 
开发者ID:BCV-Uniandes,项目名称:SMIT,代码行数:17,代码来源:utils.py

示例13: pdf2png

# 需要导入模块: from wand import color [as 别名]
# 或者: from wand.color import Color [as 别名]
def pdf2png(filename):
    from wand.image import Image
    from wand.color import Color
    with Image(filename="{}.pdf".format(filename), resolution=500) as img:
        with Image(
                width=img.width, height=img.height,
                background=Color("white")) as bg:
            bg.composite(img, 0, 0)
            bg.save(filename="{}.png".format(filename))
    os.remove('{}.pdf'.format(filename)) 
开发者ID:BCV-Uniandes,项目名称:AUNets,代码行数:12,代码来源:utils.py

示例14: render_to_jpeg

# 需要导入模块: from wand import color [as 别名]
# 或者: from wand.color import Color [as 别名]
def render_to_jpeg(html: HTML, buffer: io.BytesIO):
    png_buffer = io.BytesIO()
    html.write_png(png_buffer)
    png_buffer.seek(0)
    with Image(file=png_buffer) as image:
        image.background_color = Color('#fff')
        image.alpha_channel = 'remove'
        image.format = 'jpeg'
        image.save(file=buffer) 
开发者ID:spoqa,项目名称:html2pdf-server,代码行数:11,代码来源:html2pdfd.py


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