Tool_py:TIF轉PNG
只需更改:
“root_path” : 這為原來的踏徑文件夾
“save_path”: 這為存儲TIF轉PNG圖片的路徑文件夾
除了PNG以為,JPG等等應該都能更換,也可以相互轉換,PNG轉TIF也是可以,只需要更改
png_img = image_name.replace('.tif','.png')
中的**‘.tif’和’.png’**
原代碼:
from PIL import Image
import os
def tif_to_png(image_path,save_path,image_name):
#原圖片路徑合成
image_path_name = os.path.join(image_path,image_name)
#print(image_path_name)
#後綴名的更改
png_img = image_name.replace('.tif','.png')
#合成更改後的圖片路徑
save_path_name = os.path.join(save_path,png_img)
#print(save_path_name)
#打開原圖片
im = Image.open(image_path_name)
#存儲到目标文件
im.save(save_path_name)
if __name__ == '__main__':
#原文件夾
root_path = r'D:\you_root_path'
#存儲到的文件夾
save_path = r'D:\you_save_path'
#獲取原文件夾中的圖片
image_files = os.listdir(root_path)
#逐一張圖片轉換
for image_name in image_files:
tif_to_png(root_path,save_path,image_name)