1.批量提取图片
import requests
import re
from fontTools.ttLib import TTFont
from lxml import etree
from aip import AipOcr #pip install baidu-aip
def readme(str,i): #记事本,读取内容
f=open(str,'r+')
lines=f.readlines()
lines[i]=lines[i].strip('\r\n')
return lines[i]
for i in range(0,6):
#https://vip.gxrc.com/Public/Phone/4354E140-AF4E-4D46-B5C0-04AAD3A81F2F
#https://vip.gxrc.com/Public/Phone/113F1C6B-56E2-44DF-93A0-178E25ACC62E
#https://vip.gxrc.com/Public/Phone/FB4F6C7D-E4F9-442B-B8B8-603993782DAD
#https://vip.gxrc.com/Public/Phone/57EE4AF3-63D4-490A-A75C-98D4E5AFA5D8
#https://vip.gxrc.com/Public/Phone/266E2D9B-2ED9-4ED2-BE8A-565A8C91F5CD
#https://vip.gxrc.com/Public/Phone/6C73242B-DE0C-490B-A715-3DF7BCED7825
r=requests.get(readme('k:/zhusc/src_url.txt',i))
with open('k:/zhusc/ps/{}.png'.format(str(i)),'wb') as f:#一定要png,jpg无效
f.write(r.content)
以下代码绝大部分来自【kimol君的无聊小发明】—用python写图片格式批量处理工具
https://blog.csdn.net/kimol_justdo/article/details/111239805?utm_source=app&app_version=4.5.0
2.批量测试图片的宽度、高度
from PIL import Image
from pathlib import Path
import os
from shutil import copyfile
def resize(inImage, width, height, inplace=False):
'''
将图片调整为指定尺寸
----------------------------
参数 inImage:需要处理的图片地址
参数 width:预期图片宽度
参数 height:预期图片高度
参数 inplace:是否覆盖原文件
----------------------------
返回 outImage:压缩后的图片地址
'''
if not inplace: # 如果不覆盖
outImage = '%s-out.%s'%(inImage.split('.')[