本文整理汇总了Python中reportlab.platypus.Image方法的典型用法代码示例。如果您正苦于以下问题:Python platypus.Image方法的具体用法?Python platypus.Image怎么用?Python platypus.Image使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类reportlab.platypus
的用法示例。
在下文中一共展示了platypus.Image方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_row_data
# 需要导入模块: from reportlab import platypus [as 别名]
# 或者: from reportlab.platypus import Image [as 别名]
def get_row_data(self, source, depth, row_idx):
"""
Load the Matplotlib graph from the saved image, set its height and width
and add it to the row.
"""
header = self.get_header(source, depth, row_idx)
styles = [
RowStyle(
font=(constants.FONT, constants.FONT_SIZE_SMALL),
left_padding=constants.INDENT * (depth + 1),
text_color=colors.black,
)
]
img = Image(source["source_path"])
img.drawWidth = source["width"] * inch
img.drawHeight = source["height"] * inch
return header + RowData(
content=[img, "", "", ""], start=header.end, style=styles
)
示例2: export_plot_to_image
# 需要导入模块: from reportlab import platypus [as 别名]
# 或者: from reportlab.platypus import Image [as 别名]
def export_plot_to_image(graph_plot):
"""Convert a MatPlot plot into an image readable in the pdf."""
filename = "{}.png".format(uuid.uuid4())
temp_path = tempfile.gettempdir()
image_pathname = os.path.join(temp_path, filename)
graph_plot.savefig(image_pathname)
image = Image(image_pathname)
return image
示例3: create_img_table
# 需要导入模块: from reportlab import platypus [as 别名]
# 或者: from reportlab.platypus import Image [as 别名]
def create_img_table(self, dir):
item_tbl_data = []
item_tbl_row = []
for i, file in enumerate(os.listdir(dir)):
last_item = len(os.listdir(dir)) - 1
if ".png" in file:
img = Image(os.path.join(dir, file), inch, inch)
img_name = file.replace(".png", "")
if len(item_tbl_row) == 4:
item_tbl_data.append(item_tbl_row)
item_tbl_row = []
elif i == last_item:
item_tbl_data.append(item_tbl_row)
i_tbl = Table([[img], [Paragraph(img_name, ParagraphStyle("item name style", wordWrap='CJK'))]])
item_tbl_row.append(i_tbl)
if len(item_tbl_data) > 0:
item_tbl = Table(item_tbl_data, colWidths=125)
self.elements.append(item_tbl)
self.elements.append(Spacer(1, inch * 0.5))
示例4: get_cover_page
# 需要导入模块: from reportlab import platypus [as 别名]
# 或者: from reportlab.platypus import Image [as 别名]
def get_cover_page(self, report_id, recipient):
# title = f"{self.report_title} No.: {report_id}"
styles = getSampleStyleSheet()
headline_style = styles["Heading1"]
headline_style.alignment = TA_CENTER
headline_style.fontSize = 48
subtitle_style = styles["Heading2"]
subtitle_style.fontSize = 24
subtitle_style.leading = 26
subtitle_style.alignment = TA_CENTER
CoverPage = []
logo = os.path.join(settings.BASE_DIR, self.logo_path)
image = Image(logo, 3 * inch, 3 * inch)
CoverPage.append(image)
CoverPage.append(Spacer(1, 18))
CoverPage.append(Paragraph("CONFIDENTIAL", headline_style))
# paragraph = Paragraph(
# f"Intended for: {recipient}, Title IX Coordinator", subtitle_style)
# CoverPage.append(paragraph)
CoverPage.append(PageBreak())
return CoverPage
# entrypoints
示例5: place_label
# 需要导入模块: from reportlab import platypus [as 别名]
# 或者: from reportlab.platypus import Image [as 别名]
def place_label(self, file_name: str, label_name: str, pos: int):
"""
Place the label in the appropriate location on the page.
:param file_name:
:param label_name:
:param pos:
:return:
"""
box_info = self.label_locations[pos]
# place image on page
im = Image(file_name, LABEL_SIZE.x, LABEL_SIZE.y)
im.drawOn(self.pdf, box_info.image_start.x, box_info.image_start.y)
# place title above image
self.pdf.setFont('Helvetica-Bold', 12)
self.pdf.drawCentredString(
box_info.title_start.x + TITLE_ADJUSTMENT.x,
box_info.title_start.y + TITLE_ADJUSTMENT.y,
label_name
)
return
示例6: add_section_sequences
# 需要导入模块: from reportlab import platypus [as 别名]
# 或者: from reportlab.platypus import Image [as 别名]
def add_section_sequences(self, plots=[], stats=None):
section = self.get_section_number()
subsection = itertools.count(1)
if stats is not None:
self.story.append(Paragraph("{:d} Basecalling".format(section), self.heading_style))
self.story.append(Spacer(1, 0))
self.story.append(Paragraph("{:d}.{:d} Summary".format(section, next(subsection)), self.heading2_style))
#['Tag', 'Basecalling', 'Sum', 'Mean', 'Median', 'N50', 'Maximum']
header = ['', ''] + list(stats.columns.values[2:])
table_data = [header] + [[y if isinstance(y, str) else '{:.0f}'.format(y) for y in x] for x in stats.values]
table_style = [ ('FONTSIZE', (0,0), (-1, -1), 10),
('LINEABOVE', (0,1), (-1,1), 0.5, colors.black),
('LINEBEFORE', (2,0), (2,-1), 0.5, colors.black),
('ALIGN', (0,0), (1,-1), 'LEFT'),
('ALIGN', (2,0), (-1,-1), 'RIGHT')]
self.story.append(Table(table_data, style=table_style))
self.story.append(Spacer(1, 0))
for key, group in itertools.groupby(plots, lambda x : x[1].basecalling):
self.story.append(Paragraph('{:d}.{:d} {}:'.format(section, next(subsection), key.capitalize()), self.heading2_style))
for plot_file, plot_wildcards in sorted(list(group), key=lambda x : x[1].i):
im = svg2rlg(plot_file)
im = Image(im, width=im.width * self.plot_scale, height=im.height * self.plot_scale)
im.hAlign = 'CENTER'
self.story.append(im)
self.story.append(Spacer(1, 0))
self.story.append(Spacer(1, 0.5*cm))
示例7: add_section_alignments
# 需要导入模块: from reportlab import platypus [as 别名]
# 或者: from reportlab.platypus import Image [as 别名]
def add_section_alignments(self, counts=[], bases=[], identity=[], coverage=[]):
section = self.get_section_number()
subsection = itertools.count(1)
self.story.append(Paragraph("{:d} Alignments".format(section), self.heading_style))
self.story.append(Spacer(1, 0))
if bases:
self.story.append(Paragraph("{:d}.{:d} Mapped bases (primary alignments)".format(section, next(subsection)), self.heading2_style))
for b, label in bases:
im = svg2rlg(b)
im = Image(im, width=im.width * self.plot_scale, height=im.height * self.plot_scale)
im.hAlign = 'CENTER'
self.story.append(Paragraph(label, self.normal_style))
self.story.append(im)
self.story.append(Spacer(1, 0))
if counts:
self.story.append(Paragraph("{:d}.{:d} Mapped reads".format(section, next(subsection)), self.heading2_style))
for c, label in counts:
im = svg2rlg(c)
im = Image(im, width=im.width * self.plot_scale, height=im.height * self.plot_scale)
im.hAlign = 'CENTER'
self.story.append(Paragraph(label, self.normal_style))
self.story.append(im)
self.story.append(Spacer(1, 0))
if identity:
self.story.append(Paragraph("{:d}.{:d} Read identity (primary alignments, all aligners)".format(section, next(subsection)), self.heading2_style))
for b, label in identity:
im = svg2rlg(b)
im = Image(im, width=im.width * self.plot_scale, height=im.height * self.plot_scale)
im.hAlign = 'CENTER'
self.story.append(Paragraph(label, self.normal_style))
self.story.append(im)
self.story.append(Spacer(1, 0))
if coverage:
self.story.append(Paragraph("{:d}.{:d} Coverage".format(section, next(subsection)), self.heading2_style))
im = svg2rlg(coverage[0])
im = Image(im, width=im.width * self.plot_scale, height=im.height * self.plot_scale)
im.hAlign = 'CENTER'
self.story.append(im)
self.story.append(Spacer(1, 0))
self.story.append(Spacer(1, 0.5*cm))
示例8: add_section_methylation
# 需要导入模块: from reportlab import platypus [as 别名]
# 或者: from reportlab.platypus import Image [as 别名]
def add_section_methylation(self, coverage=[]):
section = self.get_section_number()
subsection = itertools.count(1)
self.story.append(Paragraph("{:d} Methylation".format(section), self.heading_style))
self.story.append(Spacer(1, 0))
if coverage:
self.story.append(Paragraph("{:d}.{:d} CpG coverage".format(section, next(subsection)), self.heading2_style))
for f, label in coverage:
im = svg2rlg(f)
im = Image(im, width=im.width * self.plot_scale, height=im.height * self.plot_scale)
im.hAlign = 'CENTER'
self.story.append(Paragraph(label, self.normal_style))
self.story.append(im)
self.story.append(Spacer(1, 0))
示例9: create_logo
# 需要导入模块: from reportlab import platypus [as 别名]
# 或者: from reportlab.platypus import Image [as 别名]
def create_logo(self, absolute_path):
try:
image = Image(absolute_path)
image._restrictSize(2.5 * inch, 2.5 * inch)
except:
image = Image('http://' + self.base_url +'/static/images/img-404.jpg')
image._restrictSize(1.5 * inch, 1.5 * inch)
return image
示例10: _header_footer
# 需要导入模块: from reportlab import platypus [as 别名]
# 或者: from reportlab.platypus import Image [as 别名]
def _header_footer(self, canvas, doc):
# Save the state of our canvas so we can draw on it
canvas.saveState()
style_right = ParagraphStyle(name='right', parent=self.bodystyle, fontName='arialuni',
fontSize=10, alignment=TA_RIGHT)
fieldsight_logo = Image('http://' + self.base_url +'/static/images/fs1.jpg')
fieldsight_logo._restrictSize(1.5 * inch, 1.5 * inch)
# headerleft = Paragraph("FieldSight", self.bodystyle)
headerright = Paragraph(self.project_name, style_right)
# w1, h1 = headerleft.wrap(doc.width, doc.topMargin)
w2, h2 = headerright.wrap(doc.width, doc.topMargin)
textWidth = stringWidth(self.project_name, fontName='arialuni',
fontSize=10)
fieldsight_logo.drawOn(canvas, doc.leftMargin, doc.height + doc.topMargin + 12)
headerright.drawOn(canvas, doc.leftMargin, doc.height + doc.topMargin + 20)
try:
project_logo = Image(self.project_logo)
project_logo._restrictSize(0.4 * inch, 0.4 * inch)
project_logo.drawOn(canvas, headerright.width + doc.leftMargin -0.5 * inch - textWidth, doc.height + doc.topMargin + 10)
except:
pass
# header.drawOn(canvas, doc.leftMargin + doc.width, doc.height + doc.topMargin +20)
# Footer
footer = Paragraph('Page no. '+str(canvas._pageNumber), style_right)
w, h = footer.wrap(doc.width, doc.bottomMargin)
footer.drawOn(canvas, doc.leftMargin, h + 40)
# Release the canvas
canvas.restoreState()
示例11: _create_pdf_
# 需要导入模块: from reportlab import platypus [as 别名]
# 或者: from reportlab.platypus import Image [as 别名]
def _create_pdf_(chap_save_loc):
img_list = natsorted(os.listdir(chap_save_loc))
pdf_save_loc = chap_save_loc + ".pdf"
doc = SimpleDocTemplate(pdf_save_loc, pagesize=A2)
parts = [Image(os.path.join(chap_save_loc, img)) for img in img_list]
try:
doc.build(parts)
except PermissionError:
logging.error("Missing Permission to write. File open in system editor or missing "
"write permissions.")
示例12: image
# 需要导入模块: from reportlab import platypus [as 别名]
# 或者: from reportlab.platypus import Image [as 别名]
def image(self, image_path, width=8 * cm, style=None):
img = imread(image_path)
x, y = img.shape[:2]
image = Image(image_path, width=width, height=width * x / y)
self.story.append(image)
示例13: table_model
# 需要导入模块: from reportlab import platypus [as 别名]
# 或者: from reportlab.platypus import Image [as 别名]
def table_model():
"""
添加表格
:return:
"""
template_path = current_app.config.get("REPORT_TEMPLATES")
image_path = os.path.join(template_path, 'test.jpg')
new_img = Image(image_path, width=300, height=300)
base = [
[new_img, ""],
["大类", "小类"],
["WebFramework", "django"],
["", "flask"],
["", "web.py"],
["", "tornado"],
["Office", "xlsxwriter"],
["", "openpyxl"],
["", "xlrd"],
["", "xlwt"],
["", "python-docx"],
["", "docxtpl"],
]
style = [
# 设置字体
('FONTNAME', (0, 0), (-1, -1), 'SimSun'),
# 合并单元格 (列,行)
('SPAN', (0, 0), (1, 0)),
('SPAN', (0, 2), (0, 5)),
('SPAN', (0, 6), (0, 11)),
# 单元格背景
('BACKGROUND', (0, 1), (1, 1), HexColor('#548DD4')),
# 字体颜色
('TEXTCOLOR', (0, 1), (1, 1), colors.white),
# 对齐设置
('VALIGN', (0, 0), (-1, -1), 'MIDDLE'),
('ALIGN', (0, 0), (-1, -1), 'CENTER'),
# 单元格框线
('GRID', (0, 0), (-1, -1), 0.5, colors.grey),
('BOX', (0, 0), (-1, -1), 0.5, colors.black),
]
component_table = Table(base, style=style)
return component_table
示例14: image_model
# 需要导入模块: from reportlab import platypus [as 别名]
# 或者: from reportlab.platypus import Image [as 别名]
def image_model():
"""
添加图片
:return:
"""
template_path = current_app.config.get("REPORT_TEMPLATES")
image_path = os.path.join(template_path, 'test.jpg')
new_img = Image(image_path, width=300, height=300)
return new_img