ref:https://zhuanlan.zhihu.com/p/475661402
学习的时候再看再使用,这个模块还挺有用的。
from pathlib import Path
from PIL import Image
def image_to_jpg(image_path):
"""使用Pillow将图片文件转换为.jpg文件"""
path = Path(image_path)
jpg_image_path = f'{path.parent / path.stem}_result.jpg'
Image.open(image_path).convert('RGB').save(jpg_image_path)
return image_path
path.parent:/home/jianming_ge/workplace/zhongwaiyun/fire_smoke_detect/pre_process/res_images
path.stem:jm_1055
parent, stem, suffix 是比较重要的!!
另外需要主要的是,parent是<class ‘pathlib.PosixPath’> 的格式,使用的时候要强制转成str