1 . fitz库它是pymupdf中的一个模块, 使用pip install pymupdf
import fitz
doc = fitz.open('pdf的文件路径')
totaling = doc.pageCount
for pg in range(1, totaling):
page = doc[pg]
zoom = int(100) # 变焦
rotate = int(0) # 旋转
trans = fitz.Matrix(zoom / 100.0, zoom / 100.0).preRotate(rotate)
pm = page.getPixmap(matrix=trans, alpha=False)
pm.writePNG('图片的路径')
2. 多长图片合成一张图片,图片尺寸任意
import numpy as np
from PIL import Image
def get_merge_img(img_list):
# 找出所有图片的最大宽和最大高
big_w = 0
big_h = 0
for image_file in img_list:
image_f = Image.open(image_file)
w,h = image_f.size
if w > big_w:
big_w=w
if h > big_h:
big_h = h
img_array = ''
img = ''
for i, v in enumerate(img_list):
if i == 0:
img = Image.open(v) # 打开图片
# 此处将单张图像进行缩放为统一大小,改为自己单张图像的平均尺寸即可
img = img.resize((big_w, big_h), Image.ANTIALIAS)
img_array = np.array(img) # 转化为np array对象
else:
img = Image.open(v)
# 此处将单张图像进行缩放为统一大小,改为自己单张图像的平均尺寸即可
img = img.resize((big_w, big_h), Image.ANTIALIAS)
img_array2 = np.array(img)
# img_array = np.concatenate((img_array, img_array2), axis=1) # 横向拼接
img_array = np.concatenate((img_array, img_array2), axis=0)# 纵向拼接
img = Image.fromarray(img_array)
# 保存图片
new_img_path = img_list[0].plit(".")[0]+'merge.jpg'
img.save(new_img_path)