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


Python utils.ImageReader方法代码示例

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


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

示例1: end_img

# 需要导入模块: from reportlab.lib import utils [as 别名]
# 或者: from reportlab.lib.utils import ImageReader [as 别名]
def end_img(self):
        frag = self._stack[-1]
        if not getattr(frag,'_selfClosingTag',''):
            raise ValueError('Parser failure in <img/>')
        defn = frag.cbDefn = ABag()
        defn.kind = 'img'
        defn.src = getattr(frag,'src',None)
        defn.image = ImageReader(defn.src)
        size = defn.image.getSize()
        defn.width = getattr(frag,'width',size[0])
        defn.height = getattr(frag,'height',size[1])
        defn.valign = getattr(frag,'valign','bottom')
        del frag._selfClosingTag
        self.handle_data('')
        self._pop('img')

    #### super script 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:19,代码来源:paraparser.py

示例2: makeA85Image

# 需要导入模块: from reportlab.lib import utils [as 别名]
# 或者: from reportlab.lib.utils import ImageReader [as 别名]
def makeA85Image(filename,IMG=None):
    import zlib
    img = ImageReader(filename)
    if IMG is not None: IMG.append(img)

    imgwidth, imgheight = img.getSize()
    raw = img.getRGBData()

    code = []
    append = code.append
    # this describes what is in the image itself
    append('BI')
    append('/W %s /H %s /BPC 8 /CS /%s /F [/A85 /Fl]' % (imgwidth, imgheight,_mode2cs[img.mode]))
    append('ID')
    #use a flate filter and Ascii Base 85
    assert len(raw) == imgwidth * imgheight*_mode2bpp[img.mode], "Wrong amount of data for image"
    compressed = zlib.compress(raw)   #this bit is very fast...
    encoded = asciiBase85Encode(compressed) #...sadly this may not be

    #append in blocks of 60 characters
    _chunker(encoded,code)

    append('EI')
    return code 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:26,代码来源:pdfutils.py

示例3: makeRawImage

# 需要导入模块: from reportlab.lib import utils [as 别名]
# 或者: from reportlab.lib.utils import ImageReader [as 别名]
def makeRawImage(filename,IMG=None):
    import zlib
    img = ImageReader(filename)
    if IMG is not None: IMG.append(img)

    imgwidth, imgheight = img.getSize()
    raw = img.getRGBData()

    code = []
    append = code.append
    # this describes what is in the image itself
    append('BI')
    append('/W %s /H %s /BPC 8 /CS /%s /F [/Fl]' % (imgwidth, imgheight,_mode2cs[img.mode]))
    append('ID')
    #use a flate filter
    assert len(raw) == imgwidth * imgheight*_mode2bpp[img.mode], "Wrong amount of data for image"
    compressed = zlib.compress(raw)   #this bit is very fast...

    #append in blocks of 60 characters
    _chunker(compressed,code)

    append('EI')
    return code 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:25,代码来源:pdfutils.py

示例4: end_img

# 需要导入模块: from reportlab.lib import utils [as 别名]
# 或者: from reportlab.lib.utils import ImageReader [as 别名]
def end_img(self):
        frag = self._stack[-1]
        assert getattr(frag,'_selfClosingTag',''),'Parser failure in <img/>'
        defn = frag.cbDefn = ABag()
        defn.kind = 'img'
        defn.src = getattr(frag,'src',None)
        defn.image = ImageReader(defn.src)
        size = defn.image.getSize()
        defn.width = getattr(frag,'width',size[0])
        defn.height = getattr(frag,'height',size[1])
        defn.valign = getattr(frag,'valign','bottom')
        del frag._selfClosingTag
        self.handle_data('')
        self._pop()

    #### super script 
开发者ID:gltn,项目名称:stdm,代码行数:18,代码来源:paraparser.py

示例5: makeA85Image

# 需要导入模块: from reportlab.lib import utils [as 别名]
# 或者: from reportlab.lib.utils import ImageReader [as 别名]
def makeA85Image(filename,IMG=None):
    import zlib
    img = ImageReader(filename)
    if IMG is not None: IMG.append(img)

    imgwidth, imgheight = img.getSize()
    raw = img.getRGBData()

    code = []
    append = code.append
    # this describes what is in the image itself
    append('BI')
    append('/W %s /H %s /BPC 8 /CS /%s /F [/A85 /Fl]' % (imgwidth, imgheight,_mode2cs[img.mode]))
    append('ID')
    #use a flate filter and Ascii Base 85
    assert len(raw) == imgwidth * imgheight*_mode2bpp[img.mode], "Wrong amount of data for image"
    compressed = zlib.compress(raw)   #this bit is very fast...
    encoded = _AsciiBase85Encode(compressed) #...sadly this may not be

    #append in blocks of 60 characters
    _chunker(encoded,code)

    append('EI')
    return code 
开发者ID:gltn,项目名称:stdm,代码行数:26,代码来源:pdfutils.py

示例6: drawImage

# 需要导入模块: from reportlab.lib import utils [as 别名]
# 或者: from reportlab.lib.utils import ImageReader [as 别名]
def drawImage(self, image):
        from reportlab.lib.utils import ImageReader
        im = ImageReader(image.path)
        x0 = image.x
        y0 = image.y
        x1 = image.width
        if x1 is not None: x1 += x0
        y1 = image.height
        if y1 is not None: y1 += y0
        self._canvas.drawImage(im._image,x0,y0,x1,y1) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:12,代码来源:renderPS.py

示例7: __init__

# 需要导入模块: from reportlab.lib import utils [as 别名]
# 或者: from reportlab.lib.utils import ImageReader [as 别名]
def __init__(self, filename, caption, background=None,scaleFactor=None,hAlign='CENTER',border=None):
        assert os.path.isfile(filename), 'image file %s not found' % filename
        from reportlab.lib.utils import ImageReader
        w, h = ImageReader(filename).getSize()
        self.filename = filename
        FlexFigure.__init__(self, w, h, caption, background,scaleFactor=scaleFactor,hAlign=hAlign,border=border) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:8,代码来源:figures.py

示例8: imgs_to_pdf

# 需要导入模块: from reportlab.lib import utils [as 别名]
# 或者: from reportlab.lib.utils import ImageReader [as 别名]
def imgs_to_pdf(img_path_list, target_path):
    """将一组图片合成一个pdf文件
    :param str target_path: 输出pdf文件路径
    :param list img_path_list: 要合成的图片的路径列表
    :return str target_path: 输出pdf文件路径
    """
    a4_w, a4_h = portrait(A4)

    c = canvas.Canvas(target_path, pagesize=portrait(A4))
    for img_path in img_path_list:
        img_w, img_h = ImageReader(img_path).getSize()

        if img_w / img_h > a4_w / a4_h:
            # 横图
            ratio = a4_w / img_w
            left_margin = 0
            top_margin = (a4_h - img_h * ratio) / 2
        else:
            # 竖图
            ratio = a4_h / img_h
            left_margin = (a4_w - img_w * ratio) / 2
            top_margin = 0
        c.drawImage(img_path, left_margin, top_margin, img_w * ratio, img_h * ratio)
        c.showPage()
    os.makedirs(os.path.dirname(target_path), exist_ok=True)
    c.save()
    return target_path 
开发者ID:lossme,项目名称:TencentComicBook,代码行数:29,代码来源:img2pdf.py

示例9: __init__

# 需要导入模块: from reportlab.lib import utils [as 别名]
# 或者: from reportlab.lib.utils import ImageReader [as 别名]
def __init__(self, filename, caption, background=None):
        assert os.path.isfile(filename), 'image file %s not found' % filename
        from reportlab.lib.utils import ImageReader
        w, h = ImageReader(filename).getSize()
        self.filename = filename
        FlexFigure.__init__(self, w, h, caption, background) 
开发者ID:gltn,项目名称:stdm,代码行数:8,代码来源:figures.py

示例10: pdf

# 需要导入模块: from reportlab.lib import utils [as 别名]
# 或者: from reportlab.lib.utils import ImageReader [as 别名]
def pdf(self):
        stream = BytesIO()
        pdf = canvas.Canvas(stream)
        w, h = self.img.size
        pdf.drawImage(ImageReader(self.img), *self.dimensions)

        if hasattr(self, "label"):
            w, h = self.label.size
            x, y = self.label_x, self.label_y
            pdf.drawImage(ImageReader(self.label), x, y, w, h)

        pdf.save()
        return PdfFileReader(stream).getPage(0) 
开发者ID:rammie,项目名称:pdfjinja,代码行数:15,代码来源:pdfjinja.py

示例11: image

# 需要导入模块: from reportlab.lib import utils [as 别名]
# 或者: from reportlab.lib.utils import ImageReader [as 别名]
def image(self, box, url):
        try:
            image = images.open(url, mode='pillow')
            if image.mode not in ('RGBA', 'L', 'RGB', 'CYMYK'):
                # convert to format that reportlab can recognize
                image = image.convert('RGBA')

            y = self.size[1] - box[3]
            data = ImageReader(image)
            self.canvas.drawImage(data, box.x1, y, box.width, box.height,
                                  mask='auto', preserveAspectRatio=True)
        except IOError:
            pass 
开发者ID:blockdiag,项目名称:blockdiag,代码行数:15,代码来源:pdf.py

示例12: add_image

# 需要导入模块: from reportlab.lib import utils [as 别名]
# 或者: from reportlab.lib.utils import ImageReader [as 别名]
def add_image(self, image_data: io.BytesIO, location: Sequence, dimensions: Sequence, preserve_aspect_ratio: bool=True):
        image_data.seek(0)
        image = ImageReader(Image.open(image_data))
        self.canvas.drawImage(image, location[0]*cm, location[1]*cm, width=dimensions[0]*cm,
                              height=dimensions[1]*cm, preserveAspectRatio=preserve_aspect_ratio) 
开发者ID:jrkerns,项目名称:pylinac,代码行数:7,代码来源:pdf.py

示例13: draw_image

# 需要导入模块: from reportlab.lib import utils [as 别名]
# 或者: from reportlab.lib.utils import ImageReader [as 别名]
def draw_image(self, image, alpha_channel=None):
        if not image:
            return
        if self.colorspace == uc2const.COLOR_CMYK:
            image = self.cms.convert_image(image, uc2const.IMAGE_CMYK)
        elif self.colorspace == uc2const.COLOR_RGB:
            image = self.cms.convert_image(image, uc2const.IMAGE_RGB)
        elif self.colorspace == uc2const.COLOR_GRAY:
            image = self.cms.convert_image(image, uc2const.IMAGE_GRAY)
        img = ImageReader(image)
        img.getRGBData()
        if alpha_channel:
            img._dataA = ImageReader(alpha_channel)
        self.canvas.drawImage(img, 0, 0, mask='auto') 
开发者ID:sk1project,项目名称:uniconvertor,代码行数:16,代码来源:pdfgen.py

示例14: _posting_list_header

# 需要导入模块: from reportlab.lib import utils [as 别名]
# 或者: from reportlab.lib.utils import ImageReader [as 别名]
def _posting_list_header(self, pdf, width, x1, y1, x2, y2):
        canvas = pdf.canvas

        # logo
        logo = ImageReader(self.posting_list.logo)
        canvas.drawImage(logo, x1, y2 - 10.3 * mm, height=8 * mm, preserveAspectRatio=True, anchor="sw", mask="auto")
        # head1
        canvas.setFont("Helvetica-Bold", size=14)
        canvas.drawCentredString(
            x2 - ((width - 40 * mm) / 2), y2 - 9 * mm, "Empresa Brasileira de Correios e Telégrafos".upper()
        )
        # box
        canvas.setLineWidth(0.5)
        canvas.rect(x1, y2 - 45 * mm, width, 30 * mm)
        canvas.drawCentredString(x1 + width / 2, y2 - (15 * mm) - 15, self.heading_title)
        # header info
        spacer = 5 * mm
        col_width = width / 4
        col = 0
        header = self.header_label_col1.format(
            self.posting_list.number,
            self.posting_list.contract,
            self.posting_list.posting_card.administrative_code,
            self.posting_list.posting_card,
        )
        text = Paragraph(header, style=self.label_style)
        text.wrap(col_width, 30 * mm)
        text.drawOn(canvas, x1 + spacer + col * col_width, y2 - (43 * mm))
        col = 1
        header = self.header_label_col2.format(
            self.posting_list.sender.name[:30],
            self.posting_list.contract.customer_name[:30],
            self.posting_list.sender.display_address[0][:30],
            self.posting_list.sender.display_address[1][:30],
        )
        text = Paragraph(header, style=self.label_style)
        text.wrap(col_width * 2, 30 * mm)
        text.drawOn(canvas, x1 + spacer + col * col_width, y2 - (43 * mm))
        col = 3
        header = self.header_label_col3.format(self.posting_list.sender.phone.display())
        text = Paragraph(header, style=self.label_style)
        text.wrap(col_width, 30 * mm)
        text.drawOn(canvas, x1 + spacer + col * col_width, y2 - (43 * mm))
        code = createBarcodeDrawing(
            "Code128", value=str(self.posting_list.number), width=col_width * 0.6, height=10 * mm, quiet=0
        )
        code.drawOn(canvas, x1 + spacer + col * col_width, y2 - (35 * mm))

    # noinspection PyUnusedLocal 
开发者ID:olist,项目名称:correios,代码行数:51,代码来源:pdf.py


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