import os
import random
from PIL import Image, ImageDraw
# 随机选择当前目录中的一张图片
image_files = [f for f in os.listdir('.') if f.endswith('.jpg')]
image_file = random.choice(image_files)
# 缩放图片
im = Image.open(image_file)
im = im.resize((900, 383))
# 创建 ImageDraw 对象,用于绘制图形
draw = ImageDraw.Draw(im)
# 绘制黑色正方形
x = im.width // 2 - 150
y = im.height // 2 - 150
draw.rectangle((x, y, x + 300, y + 300), fill='black')
# 绘制白色边框
draw.rectangle((x, y, x + 300, y + 300), outline='white')
# 创建 000 文件夹
if not os.path.exists('000'):
os.mkdir('000')
# 保存图片到 000 文件夹
im.save(os.path.join('000', image_file))
import random
from PIL import Image, ImageDraw
# 随机选择当前目录中的一张图片
image_files = [f for f in os.listdir('.') if f.endswith('.jpg')]
image_file = random.choice(image_files)
# 缩放图片
im = Image.open(image_file)
im = im.resize((900, 383))
# 创建 ImageDraw 对象,用于绘制图形
draw = ImageDraw.Draw(im)
# 绘制黑色正方形
x = im.width // 2 - 150
y = im.height // 2 - 150
draw.rectangle((x, y, x + 300, y + 300), fill='black')
# 绘制白色边框
draw.rectangle((x, y, x + 300, y + 300), outline='white')
# 创建 000 文件夹
if not os.path.exists('000'):
os.mkdir('000')
# 保存图片到 000 文件夹
im.save(os.path.join('000', image_file))