这篇文章将使用 Pillow 图像库 以编程方式向图像添加文本和图标层。
先决条件
- 1000x600 像素的图像。
- 一些演示图标 100x100 像素。
- 熟悉 Pipenv。
- 熟悉JupyterLab。
- 打开 安装fonts/OpenSans-Bold.ttf.
入门
让我们创建hello-img-layers
目录并安装 Pillow。
# Make the `hello-img-layers` directory
$ mkdir hello-img-layers
$ cd hello-img-layers
# Create a folder to place your icons
$ mkdir icons
# Init the virtual environment
$ pipenv --three
$ pipenv install pillow
$ pipenv install --dev jupyterlab
在这个阶段,将你的 1000x600 图像添加到根目录 ( hello-img-layers
) 作为base_img.png
(至少这是我使用的)并将你的 100x100 图标添加到hello-img-layers/icons/
.# Startup the notebook server
$ pipenv run jupyter-lab
# ... Se