python 实现tif转成jpg
from PIL import Image
import os, sys
def get_tif(df_path):
filepaths = []
for root, dirs, files in os.walk(df_path):
for file in files:
file_path = os.path.join(root, file)
a, b = os.path.split(file_path)
# a, b = os.path.split(a)
if file_path[-4:].lower() == ‘.tif’:
filepaths.append(file_path)
for dir in dirs:
dir_path = os.path.join(root, dir)
get_tif(dir_path)
return filepaths
def main():
path_folder_tif = r’D:\2-python\9-清远\JPG-tif-pdf\60-2018-永久-G2-东城江埗TIF’
path_folder_bc = r’D:\2-python\9-清远\JPG-tif-pdf\新建文件夹’
list_tif = get_tif(path_folder_tif)
for path_tif in list_tif:
path_tif_bc = path_tif.replace(path_folder_tif, path_folder_bc)[:-4] + ‘.jpg’
a, b = os.path.split(path_tif_bc)
print(a)
if not os.path.isdir(a):
os.mkdir(a)
im = Image.open(path_tif)
im.save(path_tif_bc)
if name == ‘main’:
path_folder_bc = r’D:\2-python\9-清远\JPG-tif-pdf\新建文件夹’
a, b = os.path.split(path_folder_bc)
print(a, b)