代码拉取完成,页面将自动刷新
同步操作将从 weder/doc_downloader_web 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
import os
import string
from PIL import Image
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import portrait
import sys
from tqdm import trange
def file_name(file_dir, suffix=".jpg"):
L = []
for root, dirs, files in os.walk(file_dir):
for file in files:
if os.path.splitext(file)[1] == suffix:
L.append(os.path.join(root, file))
L = sorted(L, key=lambda x: int(x.split('\\')[-1].split('/')[-1][:-4]))
return L
def conpdf(f_pdf, filedir, suffix=".jpg", scale=False):
fileList = file_name(filedir, suffix)
img = Image.open(fileList[0])
if scale and img.size[0] < img.size[1]:
# (w, h) = (940, 529)
(w, h) = (848, 1168)
else:
(w, h) = img.size
c = canvas.Canvas(f_pdf, pagesize=(w, h))
for i in trange(len(fileList)):
f = fileList[i]
(xsize, ysize) = Image.open(f).size
ratx = xsize / w
raty = ysize / h
ratxy = xsize / (1.0 * ysize)
if ratx > 1:
ratx = 0.99
if raty > 1:
raty = 0.99
rat = ratx
if ratx < raty:
rat = raty
widthx = w * rat
widthy = h * rat
widthx = widthy * ratxy
posx = (w - widthx) / 2
if posx < 0:
posx = 0
posy = (h - widthy) / 2
if posy < 0:
posy = 0
c.drawImage(f, posx, posy, widthx, widthy)
c.showPage()
c.save()
print("转码完毕")
if __name__ == "__main__":
conpdf('output.pdf', 'temp', '.png')
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。