To make some collection stations, some pictures need to be processed in batches to facilitate the regular retrieval of pictures in the background, write a Python script at a time, and rename the pictures by self-increment
from PIL import Image
import os
d = os.listdir('.')
pic_id = 1
save_path = os.path.join(os.path.abspath(''), 'save')
if not os.path.exists(save_path):
os.mkdir(save_path)
for p in [i for i in d if ('.jpg' in i) or ('.JPG' in i) or ('.png' in i)]:
im = Image.open(p)
try:
im.save(os.path.join(save_path, str(pic_id) + '.jpg'))
except Exception as e:
pass
pic_id += 1
**How to use:** Put the picture and the script in the same directory, then run the script, the picture will be automatically saved in the save
folder
Reference link: https://zmrw.net/shi-yong-python-jue-ben-pi-liang-gei-tu-pian-zhong-ming-ming/