Python教程

python 将QQ收集的照片加水印并且制成pdf

本文主要是介绍python 将QQ收集的照片加水印并且制成pdf,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
import PIL
import os
import re
from fpdf import FPDF
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont

fileAddress = r'C:\Users\1\Desktop\附件下载_行程码截图收集(收集结果)\image'      #文件文件夹位置
_fileAddress = r'C:\Users\1\Desktop\附件下载_行程码截图收集(收集结果)\image/'    #文件文件夹位置
submitAddress = r'C:\Users\1\Desktop\1/'       #文件存放文件夹位置
pdf = FPDF()
pdf.set_auto_page_break(0)


imgList = os.listdir(fileAddress)      
print(imgList)
font = ImageFont.truetype("/usr/share/fonts/chinese/simsun.ttc", 50)        #设置字体样式/大小


for file in imgList:
    a_list = re.findall(r'[\u4e00-\u9fa5]', file)
    filename = ''
    for i in  a_list:
            filename = filename + i
    file = _fileAddress + file         
    im1 = Image.open(file)

    draw = ImageDraw.Draw(im1)
    draw.text((120, 400), filename, (255, 0, 0), font = font)    #设置文字位置/内容/颜色/字体
    draw = ImageDraw.Draw(im1)

    im1.save(submitAddress + filename + '.png')


imagelist = [i for i in os.listdir(submitAddress)]


for image in sorted(imagelist):
    pdf.add_page()
    pdf.image(os.path.join(submitAddress, image), w=190, h=250)

pdf.output(os.path.join(submitAddress, "1.pdf"), "F")     #pdf名字

 

这篇关于python 将QQ收集的照片加水印并且制成pdf的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!