Skip to content

Instantly share code, notes, and snippets.

@hui-shao
Created September 17, 2023 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hui-shao/2aedffd8d9887ba23702ad506f12a290 to your computer and use it in GitHub Desktop.
Save hui-shao/2aedffd8d9887ba23702ad506f12a290 to your computer and use it in GitHub Desktop.
图像格式转换,批量版,自动处理序号。
from PIL import Image
import sys
import os
photo_input_path = r'.'
photo_save_path = r'./new'
photo_list = os.listdir(photo_input_path)
photo_list = [os.path.join(photo_input_path,i) for i in photo_list]
photo_num=len(photo_list)
zfill_n=len(str(photo_num)) + 1
if not os.path.exists(photo_save_path):
os.mkdir(photo_save_path)
for i in range(photo_num):
with Image.open(photo_list[i]) as im:
im.save(photo_save_path + "/" + str(i).zfill(zfill_n) + ".png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment