Created
September 17, 2023 12:44
-
-
Save hui-shao/2aedffd8d9887ba23702ad506f12a290 to your computer and use it in GitHub Desktop.
图像格式转换,批量版,自动处理序号。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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