本文整理汇总了Python中fitz.Matrix方法的典型用法代码示例。如果您正苦于以下问题:Python fitz.Matrix方法的具体用法?Python fitz.Matrix怎么用?Python fitz.Matrix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fitz
的用法示例。
在下文中一共展示了fitz.Matrix方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_page
# 需要导入模块: import fitz [as 别名]
# 或者: from fitz import Matrix [as 别名]
def make_page(beta):
"""Create a dummy PDF with a page, put in a box filled with above text,
and also insert some explanation. Then x-shear the text box around
its top-left corner by given value beta. The resulting page's image
is returned as a PNG stream, and the PDF discarded again.
This functions execution time determines the overall "frames" per
second ration.
"""
doc = fitz.open()
page = doc.newPage(width=pagerect.width, height=pagerect.height)
mat = fitz.Matrix(0, beta * 0.01, 1)
img = page.newShape()
img.drawRect(r)
img.finish(fill=gold, color=blue, width=0.3, morph=(r.tl, mat))
img.insertText(textpoint, itext % (beta * 0.01), fontname="cobo", fontsize=20)
img.insertTextbox(r, text, fontsize=15, rotate=90, morph=(r.tl, mat))
img.commit()
pix = page.getPixmap(alpha=False)
return pix.getImageData("pgm")
# ------------------------------------------------------------------------------
# main program
# ------------------------------------------------------------------------------
示例2: make_page
# 需要导入模块: import fitz [as 别名]
# 或者: from fitz import Matrix [as 别名]
def make_page(beta):
"""Create a dummy PDF with a page, put in a box filled with above text,
and also insert some explanation. Then rotate the text box around
its top-left corner by given angle beta. The resulting page's image
is returned as a PNG stream, and the PDF discarded again.
This functions execution time determines the overall "frames" per
second ration.
"""
doc = fitz.open()
page = doc.newPage(width=pagerect.width, height=pagerect.height)
mat = fitz.Matrix(beta)
img = page.newShape()
img.drawRect(r)
img.finish(fill=gold, color=blue, width=0.3, morph=(r.tl, mat))
img.insertText(textpoint, itext % beta, fontname="cobo", fontsize=20)
img.insertTextbox(r, text, fontsize=15, rotate=90, morph=(r.tl, mat))
img.commit()
pix = page.getPixmap(alpha=False)
return pix.getImageData("pgm")
# ------------------------------------------------------------------------------
# main program
# ------------------------------------------------------------------------------
示例3: make_page
# 需要导入模块: import fitz [as 别名]
# 或者: from fitz import Matrix [as 别名]
def make_page(beta):
"""Create a dummy PDF with a page, put in a box filled with above text,
and also insert some explanation. Then x-shear the text box around
its top-left corner by given value beta. The resulting page's image
is returned as a PNG stream, and the PDF discarded again.
This functions execution time determines the overall "frames" per
second ration.
"""
doc = fitz.open()
page = doc.newPage(width=pagerect.width, height=pagerect.height)
mat = fitz.Matrix(beta * 0.01, 0, 1)
img = page.newShape()
img.drawRect(r)
img.finish(fill=gold, color=blue, width=0.3, morph=(r.tl, mat))
img.insertText(textpoint, itext % (beta * 0.01), fontname="cobo", fontsize=20)
img.insertTextbox(r, text, fontsize=15, rotate=90, morph=(r.tl, mat))
img.commit()
pix = page.getPixmap(alpha=False)
return pix.getImageData("pgm")
# ------------------------------------------------------------------------------
# main program
# ------------------------------------------------------------------------------
示例4: render_pdf_page
# 需要导入模块: import fitz [as 别名]
# 或者: from fitz import Matrix [as 别名]
def render_pdf_page(page_data, for_cover=False):
# 图像缩放比例
zoom_matrix = fitz.Matrix(4, 4)
if for_cover:
zoom_matrix = fitz.Matrix(1, 1)
# 获取封面对应的 Pixmap 对象
# alpha 设置背景为白色
pagePixmap = page_data.getPixmap(
matrix = zoom_matrix,
alpha=False)
# 获取 image 格式
imageFormat = QtGui.QImage.Format_RGB888
# 生成 QImage 对象
pageQImage = QtGui.QImage(
pagePixmap.samples,
pagePixmap.width,
pagePixmap.height,
pagePixmap.stride,
imageFormat)
# 生成 pixmap 对象
pixmap = QtGui.QPixmap()
pixmap.convertFromImage(pageQImage)
return pixmap
示例5: render_pdf_page
# 需要导入模块: import fitz [as 别名]
# 或者: from fitz import Matrix [as 别名]
def render_pdf_page(page_data, for_cover=False):
# Draw page contents on to a pixmap
# and then return that pixmap
# Render quality is set by the following
zoom_matrix = fitz.Matrix(4, 4)
if for_cover:
zoom_matrix = fitz.Matrix(1, 1)
pagePixmap = page_data.getPixmap(
matrix=zoom_matrix,
alpha=False) # Sets background to White
imageFormat = QtGui.QImage.Format_RGB888 # Set to Format_RGB888 if alpha
pageQImage = QtGui.QImage(
pagePixmap.samples,
pagePixmap.width,
pagePixmap.height,
pagePixmap.stride,
imageFormat)
# The cover page doesn't require conversion into a Pixmap
if for_cover:
return pageQImage
pixmap = QtGui.QPixmap()
pixmap.convertFromImage(pageQImage)
return pixmap
示例6: get_page
# 需要导入模块: import fitz [as 别名]
# 或者: from fitz import Matrix [as 别名]
def get_page(pno, zoom=0):
"""Return a PNG image for a document page number. If zoom is other than 0, one of the 4 page quadrants are zoomed-in instead and the corresponding clip returned.
"""
dlist = dlist_tab[pno] # get display list
if not dlist: # create if not yet there
dlist_tab[pno] = doc[pno].getDisplayList()
dlist = dlist_tab[pno]
r = dlist.rect # page rectangle
mp = r.tl + (r.br - r.tl) * 0.5 # rect middle point
mt = r.tl + (r.tr - r.tl) * 0.5 # middle of top edge
ml = r.tl + (r.bl - r.tl) * 0.5 # middle of left edge
mr = r.tr + (r.br - r.tr) * 0.5 # middle of right egde
mb = r.bl + (r.br - r.bl) * 0.5 # middle of bottom edge
mat = fitz.Matrix(2, 2) # zoom matrix
if zoom == 1: # top-left quadrant
clip = fitz.Rect(r.tl, mp)
elif zoom == 4: # bot-right quadrant
clip = fitz.Rect(mp, r.br)
elif zoom == 2: # top-right
clip = fitz.Rect(mt, mr)
elif zoom == 3: # bot-left
clip = fitz.Rect(ml, mb)
if zoom == 0: # total page
pix = dlist.getPixmap(alpha=False)
else:
pix = dlist.getPixmap(alpha=False, matrix=mat, clip=clip)
return pix.getPNGData() # return the PNG image
示例7: render_pdf_page
# 需要导入模块: import fitz [as 别名]
# 或者: from fitz import Matrix [as 别名]
def render_pdf_page(page_data, *, size=(1, 1)):
# 图像缩放比例
# zoom_matrix = fitz.Matrix(4, 4)
# if for_cover:
a, b = size
zoom_matrix = fitz.Matrix(a, b)
# 获取封面对应的 Pixmap 对象
# alpha 设置背景为白色
pagePixmap = page_data.getPixmap(
matrix=zoom_matrix,
alpha=False)
# 获取 image 格式
imageFormat = QtGui.QImage.Format_RGB888
# 生成 QImage 对象
pageQImage = QtGui.QImage(
pagePixmap.samples,
pagePixmap.width,
pagePixmap.height,
pagePixmap.stride,
imageFormat)
# 生成 pixmap 对象
pixmap = QtGui.QPixmap()
pixmap.convertFromImage(pageQImage)
return pixmap
示例8: get_page
# 需要导入模块: import fitz [as 别名]
# 或者: from fitz import Matrix [as 别名]
def get_page(page_num, page_display_list_cache, document, window_size, zoom=False):
"""Return a `tkinter.PhotoImage` or a PNG image for a document page number.
- The `page_num` argument is a 0-based page number.
- The `zoom` argument is the top-left of old clip rect, and one of -1, 0,
+1 for dim. x or y to indicate the arrow key pressed.
- The `max_size` argument is the (width, height) of available image area.
"""
zoom_x = 1
zoom_y = 1
scale = fitz.Matrix(zoom_x, zoom_y)
page_display_list = page_display_list_cache[page_num]
if not page_display_list: # Create if not yet there.
page_display_list_cache[page_num] = document[page_num].getDisplayList()
page_display_list = page_display_list_cache[page_num]
rect = page_display_list.rect # The page rectangle.
clip = rect
# Make sure that the image will fits the screen.
zoom_0 = 1
if window_size:
zoom_0 = min(1, window_size[0] / rect.width, window_size[1] / rect.height)
if zoom_0 == 1:
zoom_0 = min(window_size[0] / rect.width, window_size[1] / rect.height)
mat_0 = fitz.Matrix(zoom_0, zoom_0)
if not zoom: # Show the total page.
pixmap = page_display_list.getPixmap(matrix=mat_0, alpha=False)
else:
w2 = rect.width / 2 # we need these ...
h2 = rect.height / 2 # a few times
clip = rect * 0.5 # clip rect size is a quarter page
tl = zoom[0] # old top-left
tl.x += zoom[1] * (w2 / 2) # adjust top-left ...
tl.x = max(0, tl.x) # according to ...
tl.x = min(w2, tl.x) # arrow key ...
tl.y += zoom[2] * (h2 / 2) # provided, but ...
tl.y = max(0, tl.y) # stay within ...
tl.y = min(h2, tl.y) # the page rect
clip = fitz.Rect(tl, tl.x + w2, tl.y + h2)
# Clip rect is ready, now fill it.
mat = mat_0 * fitz.Matrix(2, 2) # The zoom matrix.
pixmap = page_display_list.getPixmap(alpha=False, matrix=mat, clip=clip)
image_ppm = pixmap.getImageData("ppm") # Make PPM image from pixmap for tkinter.
return image_ppm, clip.tl # Return image, clip position.
示例9: get_page
# 需要导入模块: import fitz [as 别名]
# 或者: from fitz import Matrix [as 别名]
def get_page(pno, zoom = False, max_size = None, first = False):
"""Return a PNG image for a document page number.
"""
dlist = dlist_tab[pno] # get display list of page number
if not dlist: # create if not yet there
dlist_tab[pno] = doc[pno].getDisplayList()
dlist = dlist_tab[pno]
r = dlist.rect # the page rectangle
clip = r
# ensure image fits screen:
# exploit, but do not exceed width or height
zoom_0 = 1
if max_size:
zoom_0 = min(1, max_size[0] / r.width, max_size[1] / r.height)
if zoom_0 == 1:
zoom_0 = min(max_size[0] / r.width, max_size[1] / r.height)
mat_0 = fitz.Matrix(zoom_0, zoom_0)
if not zoom: # show total page
pix = dlist.getPixmap(matrix = mat_0, alpha=False)
else:
mp = r.tl + (r.br - r.tl) * 0.5 # page rect center
w2 = r.width / 2
h2 = r.height / 2
clip = r * 0.5
tl = zoom[0] # old top-left
tl.x += zoom[1] * (w2 / 2)
tl.x = max(0, tl.x)
tl.x = min(w2, tl.x)
tl.y += zoom[2] * (h2 / 2)
tl.y = max(0, tl.y)
tl.y = min(h2, tl.y)
clip = fitz.Rect(tl, tl.x + w2, tl.y + h2)
mat = mat_0 * fitz.Matrix(2, 2) # zoom matrix
pix = dlist.getPixmap(alpha=False, matrix=mat, clip=clip)
if first: # first call: tkinter still inactive
img = pix.getPNGData() # so use fitz png output
else: # else take tk photo image
pilimg = Image.frombytes("RGB", [pix.width, pix.height], pix.samples)
img = ImageTk.PhotoImage(pilimg)
return img, clip.tl # return image, clip position
示例10: get_page
# 需要导入模块: import fitz [as 别名]
# 或者: from fitz import Matrix [as 别名]
def get_page(pno, zoom=False, max_size=None, first=False):
"""Return a PNG image for a document page number.
"""
dlist = dlist_tab[pno] # get display list of page number
if not dlist: # create if not yet there
dlist_tab[pno] = doc[pno].getDisplayList()
dlist = dlist_tab[pno]
r = dlist.rect # the page rectangle
clip = r
# ensure image fits screen:
# exploit, but do not exceed width or height
zoom_0 = 1
if max_size:
zoom_0 = min(1, max_size[0] / r.width, max_size[1] / r.height)
if zoom_0 == 1:
zoom_0 = min(max_size[0] / r.width, max_size[1] / r.height)
mat_0 = fitz.Matrix(zoom_0, zoom_0)
if not zoom: # show total page
pix = dlist.getPixmap(matrix=mat_0, alpha=False)
else:
mp = r.tl + (r.br - r.tl) * 0.5 # page rect center
w2 = r.width / 2
h2 = r.height / 2
clip = r * 0.5
tl = zoom[0] # old top-left
tl.x += zoom[1] * (w2 / 2)
tl.x = max(0, tl.x)
tl.x = min(w2, tl.x)
tl.y += zoom[2] * (h2 / 2)
tl.y = max(0, tl.y)
tl.y = min(h2, tl.y)
clip = fitz.Rect(tl, tl.x + w2, tl.y + h2)
mat = mat_0 * fitz.Matrix(2, 2) # zoom matrix
pix = dlist.getPixmap(alpha=False, matrix=mat, clip=clip)
if first: # first call: tkinter still inactive
img = pix.getPNGData() # so use fitz png output
else: # else take tk photo image
pilimg = Image.frombytes("RGB", [pix.width, pix.height], pix.samples)
img = ImageTk.PhotoImage(pilimg)
return img, clip.tl # return image, clip position
示例11: get_page
# 需要导入模块: import fitz [as 别名]
# 或者: from fitz import Matrix [as 别名]
def get_page(pno, zoom=False, max_size=None):
"""Return a tkinter.PhotoImage or a PNG image for a document page number.
:arg int pno: 0-based page number
:arg zoom: top-left of old clip rect, and one of -1, 0, +1 for dim. x or y
to indicate the arrow key pressed
:arg max_size: (width, height) of available image area
:arg bool first: if True, we cannot use tkinter
"""
dlist = dlist_tab[pno] # get display list of page number
if not dlist: # create if not yet there
dlist_tab[pno] = doc[pno].getDisplayList()
dlist = dlist_tab[pno]
r = dlist.rect # the page rectangle
clip = r
# ensure image fits screen:
# exploit, but do not exceed width or height
zoom_0 = 1
if max_size:
zoom_0 = min(1, max_size[0] / r.width, max_size[1] / r.height)
if zoom_0 == 1:
zoom_0 = min(max_size[0] / r.width, max_size[1] / r.height)
mat_0 = fitz.Matrix(zoom_0, zoom_0)
if not zoom: # show the total page
pix = dlist.getPixmap(matrix=mat_0, alpha=False)
else:
w2 = r.width / 2 # we need these ...
h2 = r.height / 2 # a few times
clip = r * 0.5 # clip rect size is a quarter page
tl = zoom[0] # old top-left
tl.x += zoom[1] * (w2 / 2) # adjust topl-left ...
tl.x = max(0, tl.x) # according to ...
tl.x = min(w2, tl.x) # arrow key ...
tl.y += zoom[2] * (h2 / 2) # provided, but ...
tl.y = max(0, tl.y) # stay within ...
tl.y = min(h2, tl.y) # the page rect
clip = fitz.Rect(tl, tl.x + w2, tl.y + h2)
# clip rect is ready, now fill it
mat = mat_0 * fitz.Matrix(2, 2) # zoom matrix
pix = dlist.getPixmap(alpha=False, matrix=mat, clip=clip)
img = pix.getImageData("ppm") # make PPM image from pixmap for tkinter
return img, clip.tl # return image, clip position
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# get physical screen dimension to determine the page image max size
# ------------------------------------------------------------------------------