请使用python语言生成一张白色背景由正方形的黑色像素色块组成的骷髅头图片
时间: 2024-05-19 14:15:31 浏览: 176
python+opencv生成较真实的车牌号码图片
以下是生成骷髅头图片的Python代码:
```python
from PIL import Image
# 设置图片大小和像素块大小
image_size = 200
pixel_size = 20
# 创建白色背景图片
image = Image.new('RGB', (image_size, image_size), 'white')
# 绘制黑色像素块组成的骷髅头
for i in range(5):
for j in range(5):
if (i == 0 and j in [1, 3]) or (i == 1 and j == 2) or \
(i == 2 and j in [0, 4]) or (i == 3 and j in [0, 4]) or \
(i == 4 and j in [1, 3]):
pixel = Image.new('RGB', (pixel_size, pixel_size), 'black')
image.paste(pixel, (i*pixel_size, j*pixel_size))
# 保存图片
image.save('skull.png')
```
生成的图片如下所示:
![skull.png](https://i.loli.net/2022/02/14/4Q2FyHgWj9X7vNl.png)
阅读全文