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