下面是一个使用Python生成图片验证码的简单示例:

from PIL import Image, ImageDraw, ImageFont
import random

def generate_captcha(text, width, height, font_path, font_size):
    # 创建一个空白图片
    image = Image.new('RGB', (width, height), (255, 255, 255))
    draw = ImageDraw.Draw(image)

    # 加载字体
    font = ImageFont.truetype(font_path, font_size)

    # 绘制验证码文本
    text_width, text_height = draw.textsize(text, font=font)
    x = (width - text_width) // 2
    y = (height - text_height) // 2
    draw.text((x, y), text, font=font, fill=(0, 0, 0))

    # 添加噪点
    for _ in range(100):
        x = random.randint(0, width - 1)
        y = random.randint(0, height - 1)
        draw.point((x, y), fill=(0, 0, 0))

    # 添加干扰线
    for _ in range(5):
        x1 = random.randint(0, width - 1)
        y1 = random.randint(0, height - 1)
        x2 = random.randint(0, width - 1)
        y2 = random.randint(0, height - 1)
        draw.line([(x1, y1), (x2, y2)], fill=(0, 0, 0))

    return image

# 生成验证码
text = ''.join(random.choices('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', k=4))
image = generate_captcha(text, 200, 80, 'arial.ttf', 36)
image.show()

请确保已经安装Pillow库(pip install pillow)。这个示例会生成一个包含随机四个字母和数字的验证码图片,并显示在屏幕上。你可以根据需要调整图片的宽度、高度、字体路径和字体大小等参数。