當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。