知行编程网知行编程网  2022-04-18 10:00 知行编程网 隐藏边栏 |   抢沙发  9 
文章评分 0 次,平均分 0.0
<p style="margin-left: 16px;margin-right: 16px;text-align: left;"><span style="background-color: rgb(255, 255, 255);font-family: Optima-Regular, PingFangTC-light;text-align: justify;color: inherit;font-size: 15px;letter-spacing: 1px;">本文源于《</span><span style="background-color: rgb(255, 255, 255);font-size: 15px;letter-spacing: 1px;">用Python自动化生成倒计时图片</span><span style="letter-spacing: 1px;"><span style="font-size: 15px;background-color: rgb(255, 255, 255);font-family: Optima-Regular, PingFangTC-light;text-align: justify;color: inherit;">》的想法(来源:</span><span style="background-color: rgb(255, 255, 255);font-family: Optima-Regular, PingFangTC-light;text-align: justify;color: inherit;font-size: 15px;">法纳斯特 | 作者:小F)</span></span></p><section style="white-space: normal;text-align: justify;margin-left: 16px;margin-right: 16px;"><span style="background-color: rgb(255, 255, 255);font-family: Optima-Regular, PingFangTC-light;font-size: 15px;letter-spacing: 1px;"><br  /></span></section><section style="white-space: normal;text-align: justify;margin-left: 16px;margin-right: 16px;"><span style="letter-spacing: 1px;"><span style="background-color: rgb(255, 255, 255);font-family: Optima-Regular, PingFangTC-light;font-size: 15px;">并结合《python繁琐工作自动化》一书,增添了一些设计元素,</span><span style="font-family: Optima-Regular, PingFangTC-light;font-size: 15px;background-color: rgb(214, 214, 214);">制作了新一版本的新年倒计时海报。</span></span></section><p style="margin-left: 16px;margin-right: 16px;"><br  /></p><p style="margin-left: 16px;margin-right: 16px;"><span style="color: rgb(255, 255, 255);font-family: Optima-Regular, PingFangTC-light;background-color: rgb(255, 169, 0);font-size: 15px;letter-spacing: 1px;"><br  /></span></p><section style="margin-left: 16px;margin-right: 16px;"><span style="font-family: Optima-Regular, PingFangTC-light;text-align: left;white-space: pre;background-color: rgb(255, 169, 0);font-size: 20px;color: rgb(255, 255, 255);letter-spacing: 1px;">000.</span></section><section style="margin-left: 16px;margin-right: 16px;"><span style="font-size: 20px;font-family: Optima-Regular, PingFangTC-light;letter-spacing: 1px;">效果预览</span></section>

用Python制作“除夕夜倒计时”海报,新的一年你准备好了么?
用Python制作“除夕夜倒计时”海报,新的一年你准备好了么?
<section style="text-align: justify;margin-left: 16px;margin-right: 16px;"><span style="font-family: 'Helvetica Neue', Helvetica, 'Hiragino Sans GB', 'Microsoft YaHei', Arial, sans-serif;letter-spacing: 0px;"></span></section><pre><section style="margin-left: 16px;margin-right: 16px;"><span style="font-size: 20px;background-color: rgb(255, 169, 0);color: rgb(255, 255, 255);text-align: left;font-family: Optima-Regular, PingFangTC-light;letter-spacing: 1px;"><br  /></span></section><section style="margin-left: 16px;margin-right: 16px;"><span style="font-size: 20px;background-color: rgb(255, 169, 0);color: rgb(255, 255, 255);text-align: left;font-family: Optima-Regular, PingFangTC-light;letter-spacing: 1px;">001.</span><br  /></section><section style="margin-left: 16px;margin-right: 16px;"><span style="font-family: Optima-Regular, PingFangTC-light;font-size: 20px;letter-spacing: 1px;">创建图像</span><br  /></section>


RGBA 值是一组数字,

红、绿、蓝和alpha(透明度)

代表0(根本没有)到255(最高)的整数


在 Pillow 中,
RGBA 值表示为四个整数值的元组。

例如,红色表示为(255,0,0,255)

这种颜色中红的值为最大,没有绿和蓝,
并且alpha 值最大,这意味着它完全不透明。
<section style="margin-left: 16px;margin-right: 16px;"><br  /></section><blockquote class="js_blockquote_wrap" data-type="2" data-url="" data-author-name="" data-content-utf8-length="81" data-source-title=""><section class="js_blockquote_digest"><section><p style="margin-left: 8px;margin-right: 8px;"><span style="font-family: Optima-Regular, PingFangTC-light;font-size: 15px;letter-spacing: 1px;">绿色:(0,255,0,255)</span></p><p style="margin-left: 8px;margin-right: 8px;"><span style="font-family: Optima-Regular, PingFangTC-light;font-size: 15px;letter-spacing: 1px;">蓝色:(0,0,255,255)</span></p><p style="margin-left: 8px;margin-right: 8px;"><span style="font-family: Optima-Regular, PingFangTC-light;font-size: 15px;letter-spacing: 1px;">白色是各种颜色的组合:(255,255,255,255)</span></p><p style="margin-left: 8px;margin-right: 8px;"><span style="font-family: Optima-Regular, PingFangTC-light;font-size: 15px;letter-spacing: 1px;">而黑色没有任何颜色:(0,0,0,255)</span></p></section></section></blockquote><pre style="color: rgb(62, 62, 62);font-size: 16px;"><section style="margin-right: 16px;margin-left: 16px;"><br  /></section><section style="margin-right: 16px;margin-left: 16px;"></section><section style="text-align: center;"><span style="font-weight: 700;text-align: start;background-color: rgb(255, 255, 255);color: rgb(136, 136, 136);font-family: Optima-Regular, PingFangTC-light;letter-spacing: 1px;font-size: 12px;">灵感来源:2019新年倒计时动态海报系列</span></section>

Pillow 提供ImageColor.getcolor()函数,
所以你不必记住想用的颜色的RGBA值。

该函数接受颜色名称字符串作为第一个参数,
字符串'RGBA'作为第二个参数,
返回一个RGBA 元组。



本例中的图像尺寸和颜色:

尺寸:1000*2160

颜色:(174,60,58,255)

相关代码如下:


from PIL import Image, ImageDraw, ImageFont
import os

# 创建图像,并设置尺寸和颜色
im = Image.new('RGBA', (10002160), (174,60,58,255))
draw = ImageDraw.Draw(im)

<section style="margin-left: 16px;margin-right: 16px;"><br  /></section><section style="margin-left: 16px;margin-right: 16px;"><br  /></section><pre style="color: rgb(62, 62, 62);font-size: 16px;"><section style="margin-right: 16px;margin-left: 16px;"><span style="background-color: rgb(255, 169, 0);color: rgb(255, 255, 255);font-family: Optima-Regular, PingFangTC-light;text-align: left;font-size: 20px;letter-spacing: 1px;">002.</span><br  /></section><p style="margin-left: 16px;margin-right: 16px;"><span style="font-family: Optima-Regular, PingFangTC-light;font-size: 20px;letter-spacing: 1px;">设置字体</span></p>

要设置字体和大小,

我们首先将文件夹名称保存在fontsFolde中。


然后调用ImageFont.truetype(),

传入我们想要的字体的.TTF 文件,

之后是表示字体大小的整数。


将ImageFont.truetype()返回的Font对象

保存在arialFont这样的变量中,

然后将该变量传入text(),

作为最后的关键字参数。


<section style="line-height: 18px;font-size: 14px;letter-spacing: 0px;font-family: Consolas, Inconsolata, Courier, monospace;border-radius: 0px;color: rgb(169, 183, 198);background: rgb(40, 43, 46);padding: 0.5em;margin-left: 16px;margin-right: 16px;overflow-wrap: normal !important;word-break: normal !important;overflow: auto !important;display: -webkit-box !important;"><span style="line-height: inherit;color: rgb(128, 128, 128);font-size: 15px;letter-spacing: normal;overflow-wrap: inherit !important;word-break: inherit !important;"># 使用使用的字体及字号</span><br  /><span style="letter-spacing: normal;"><span style="font-size: 15px;">fontsFolder = <span style="font-size: 15px;line-height: inherit;color: rgb(238, 220, 112);overflow-wrap: inherit !important;word-break: inherit !important;">'D:/05.python_code/00.py_projects/new_year_last'</span></span><span style="line-height: inherit;color: rgb(238, 220, 112);font-size: 15px;overflow-wrap: inherit !important;word-break: inherit !important;"></span></span><br  /><span style="font-size: 15px;letter-spacing: normal;">font1 = ImageFont.truetype(os.path.join(fontsFolder, <span style="font-size: 15px;line-height: inherit;color: rgb(238, 220, 112);overflow-wrap: inherit !important;word-break: inherit !important;">'wenzangshufang.ttf'</span>), <span style="font-size: 15px;line-height: inherit;color: rgb(174, 135, 250);overflow-wrap: inherit !important;word-break: inherit !important;">580</span>)</span><br  /><span style="font-size: 15px;letter-spacing: normal;">font2 = ImageFont.truetype(os.path.join(fontsFolder, <span style="font-size: 15px;line-height: inherit;color: rgb(238, 220, 112);overflow-wrap: inherit !important;word-break: inherit !important;">'SourceHanSerifCN-SemiBold.otf'</span>), <span style="font-size: 15px;line-height: inherit;color: rgb(174, 135, 250);overflow-wrap: inherit !important;word-break: inherit !important;">90</span>)</span><br  /><span style="font-size: 15px;letter-spacing: normal;">font3 = ImageFont.truetype(os.path.join(fontsFolder, <span style="font-size: 15px;line-height: inherit;color: rgb(238, 220, 112);overflow-wrap: inherit !important;word-break: inherit !important;">'SourceHanSerifCN-SemiBold.otf'</span>), <span style="font-size: 15px;line-height: inherit;color: rgb(174, 135, 250);overflow-wrap: inherit !important;word-break: inherit !important;">180</span>)</span><span style="font-size: 15px;letter-spacing: 0.5px;"></span><br  /></section>
<section style="margin-left: 16px;margin-right: 16px;"><br  /></section>
<pre style="color: rgb(62, 62, 62);font-size: 16px;"><section style="margin-right: 16px;margin-left: 16px;"><br  /></section><section style="margin-right: 16px;margin-left: 16px;"><span style="background-color: rgb(255, 169, 0);color: rgb(255, 255, 255);font-family: Optima-Regular, PingFangTC-light;text-align: left;font-size: 20px;letter-spacing: 1px;">003.</span><br  /></section><p style="margin-left: 16px;margin-right: 16px;"><span style="font-family: Optima-Regular, PingFangTC-light;font-size: 20px;letter-spacing: 1px;">绘制矩形</span></p>

rectangle(xy, fill, outline) 方法
绘制一个矩形

xy 参数是一个矩形元组,

形式为(left,top, right, bottom)。


left 和top 值指定了矩形左上角的x 和y 坐标,

right 和bottom 指定了矩形的右下角。


可选的fill 参数是颜色,将填充该矩形的内部。

可选的outline 参数是矩形轮廓的颜色。


<section style="line-height: 18px;font-size: 14px;letter-spacing: 0px;font-family: Consolas, Inconsolata, Courier, monospace;border-radius: 0px;color: rgb(169, 183, 198);background: rgb(40, 43, 46);padding: 0.5em;margin-left: 16px;margin-right: 16px;overflow-wrap: normal !important;word-break: normal !important;overflow: auto !important;display: -webkit-box !important;"><span style="line-height: inherit;color: rgb(128, 128, 128);font-size: 15px;letter-spacing: 1px;overflow-wrap: inherit !important;word-break: inherit !important;"><span style="line-height: inherit;color: rgb(128, 128, 128);font-size: 15px;letter-spacing: normal;overflow-wrap: inherit !important;word-break: inherit !important;"># 绘制矩形</span></span><br  /><span style="font-size: 15px;letter-spacing: normal;">left = pos_x_3</span><br  /><span style="font-size: 15px;letter-spacing: normal;">top = <span style="font-size: 15px;line-height: inherit;color: rgb(174, 135, 250);overflow-wrap: inherit !important;word-break: inherit !important;">1750</span></span><span style="line-height: inherit;color: rgb(174, 135, 250);font-size: 15px;letter-spacing: normal;overflow-wrap: inherit !important;word-break: inherit !important;"></span><br  /><span style="font-size: 15px;letter-spacing: normal;">right = pos_x_3 + txtSize_3[<span style="font-size: 15px;line-height: inherit;color: rgb(174, 135, 250);overflow-wrap: inherit !important;word-break: inherit !important;">0</span>]</span><br  /><span style="font-size: 15px;letter-spacing: normal;">bottom = <span style="font-size: 15px;line-height: inherit;color: rgb(174, 135, 250);overflow-wrap: inherit !important;word-break: inherit !important;">1700</span> + txtSize_3[<span style="font-size: 15px;line-height: inherit;color: rgb(174, 135, 250);overflow-wrap: inherit !important;word-break: inherit !important;">1</span>]</span><br  /><span style="font-size: 15px;letter-spacing: normal;">draw.rectangle((left, top, right, bottom), fill=(<span style="font-size: 15px;line-height: inherit;color: rgb(174, 135, 250);overflow-wrap: inherit !important;word-break: inherit !important;">217</span>, <span style="font-size: 15px;line-height: inherit;color: rgb(174, 135, 250);overflow-wrap: inherit !important;word-break: inherit !important;">217</span>, <span style="font-size: 15px;line-height: inherit;color: rgb(174, 135, 250);overflow-wrap: inherit !important;word-break: inherit !important;">217</span>, <span style="font-size: 15px;line-height: inherit;color: rgb(174, 135, 250);overflow-wrap: inherit !important;word-break: inherit !important;">255</span>))</span><br  /></section>
<section style="margin-left: 16px;margin-right: 16px;"><br  /></section>
<pre style="font-family: 'Helvetica Neue', Helvetica, 'Hiragino Sans GB', 'Microsoft YaHei', Arial, sans-serif;color: rgb(62, 62, 62);font-size: 16px;"><section style="margin-right: 16px;margin-left: 16px;"><br  /></section><section style="margin-right: 16px;margin-left: 16px;"><span style="background-color: rgb(255, 169, 0);color: rgb(255, 255, 255);font-family: Optima-Regular, PingFangTC-light;text-align: left;font-size: 20px;letter-spacing: 1px;">004.</span><br  /></section><p style="margin-left: 16px;margin-right: 16px;"><span style="font-family: Optima-Regular, PingFangTC-light;font-size: 20px;letter-spacing: 1px;">绘制文本</span></p>

ImageDraw 对象还有text()方法,
用于在图像上绘制文本。

text()方法有4 个参数:

xy参数是两个整数的元组,指定文本区域的左上角

text 参数是想写入的文本字符串

可选参数fill 是文本的颜色

可选参数font 是一个ImageFont 对象,

用于设置文本的字体和大小


因为通常很难预先知道一块文本
在给定的字体下的大小,
所以ImageDraw 模块也提供了textsize()方法。

textsize()方法返回一个两整数元组,
表示如果以指定的字体写入图像,
文本的宽度和高度。


<section style="line-height: 18px;font-size: 14px;letter-spacing: 0px;font-family: Consolas, Inconsolata, Courier, monospace;border-radius: 0px;color: rgb(169, 183, 198);background: rgb(40, 43, 46);padding: 0.5em;margin-left: 16px;margin-right: 16px;overflow-wrap: normal !important;word-break: normal !important;overflow: auto !important;display: -webkit-box !important;"><span style="line-height: inherit;color: rgb(128, 128, 128);font-size: 15px;letter-spacing: normal;overflow-wrap: inherit !important;word-break: inherit !important;"># 计算各文本的放置位置</span><br  /><span style="font-size: 15px;letter-spacing: normal;">txtSize_1 = draw.textsize(<span style="font-size: 15px;line-height: inherit;color: rgb(238, 220, 112);overflow-wrap: inherit !important;word-break: inherit !important;">'距 离 新 年 还 有'</span>, font2)</span><br  /><span style="letter-spacing: normal;"><span style="font-size: 15px;">pos_x_1 = (<span style="font-size: 15px;line-height: inherit;color: rgb(174, 135, 250);overflow-wrap: inherit !important;word-break: inherit !important;">1000</span> - txtSize_1[<span style="font-size: 15px;line-height: inherit;color: rgb(174, 135, 250);overflow-wrap: inherit !important;word-break: inherit !important;">0</span>]) / <span style="font-size: 15px;line-height: inherit;color: rgb(174, 135, 250);overflow-wrap: inherit !important;word-break: inherit !important;">2</span></span><span style="line-height: inherit;color: rgb(174, 135, 250);font-size: 15px;overflow-wrap: inherit !important;word-break: inherit !important;"></span></span><br  /><span style="font-size: 15px;letter-spacing: normal;">txtSize_2 = draw.textsize(<span style="font-size: 15px;line-height: inherit;color: rgb(238, 220, 112);overflow-wrap: inherit !important;word-break: inherit !important;">'天'</span>, font2)</span><br  /><span style="letter-spacing: normal;"><span style="font-size: 15px;">pos_x_2 = (<span style="font-size: 15px;line-height: inherit;color: rgb(174, 135, 250);overflow-wrap: inherit !important;word-break: inherit !important;">1000</span> - txtSize_2[<span style="font-size: 15px;line-height: inherit;color: rgb(174, 135, 250);overflow-wrap: inherit !important;word-break: inherit !important;">0</span>]) / <span style="font-size: 15px;line-height: inherit;color: rgb(174, 135, 250);overflow-wrap: inherit !important;word-break: inherit !important;">2</span></span><span style="line-height: inherit;color: rgb(174, 135, 250);font-size: 15px;overflow-wrap: inherit !important;word-break: inherit !important;"></span></span><br  /><br  /><span style="font-size: 15px;letter-spacing: normal;">wenhou = [<span style="font-size: 15px;line-height: inherit;color: rgb(238, 220, 112);overflow-wrap: inherit !important;word-break: inherit !important;">"除夕夜"</span>, <span style="font-size: 15px;line-height: inherit;color: rgb(238, 220, 112);overflow-wrap: inherit !important;word-break: inherit !important;">"贴春联"</span>, <span style="font-size: 15px;line-height: inherit;color: rgb(238, 220, 112);overflow-wrap: inherit !important;word-break: inherit !important;">"把面发"</span>, <span style="font-size: 15px;line-height: inherit;color: rgb(238, 220, 112);overflow-wrap: inherit !important;word-break: inherit !important;">"置新衣"</span>, <span style="font-size: 15px;line-height: inherit;color: rgb(238, 220, 112);overflow-wrap: inherit !important;word-break: inherit !important;">"煮肉肉"</span>, <span style="font-size: 15px;line-height: inherit;color: rgb(238, 220, 112);overflow-wrap: inherit !important;word-break: inherit !important;">"买年货"</span>, <span style="font-size: 15px;line-height: inherit;color: rgb(238, 220, 112);overflow-wrap: inherit !important;word-break: inherit !important;">"大扫除"</span>, <span style="font-size: 15px;line-height: inherit;color: rgb(238, 220, 112);overflow-wrap: inherit !important;word-break: inherit !important;">"祭灶台"</span>]</span><br  /><span style="font-size: 15px;letter-spacing: normal;">txtSize_3 = draw.textsize(wenhou[i<span style="font-size: 15px;line-height: inherit;color: rgb(174, 135, 250);overflow-wrap: inherit !important;word-break: inherit !important;">-1</span>], font3)</span><br  /><span style="letter-spacing: normal;"><span style="font-size: 15px;">pos_x_3 = (<span style="font-size: 15px;line-height: inherit;color: rgb(174, 135, 250);overflow-wrap: inherit !important;word-break: inherit !important;">1000</span> - txtSize_3[<span style="font-size: 15px;line-height: inherit;color: rgb(174, 135, 250);overflow-wrap: inherit !important;word-break: inherit !important;">0</span>]) / <span style="font-size: 15px;line-height: inherit;color: rgb(174, 135, 250);overflow-wrap: inherit !important;word-break: inherit !important;">2</span></span><span style="line-height: inherit;color: rgb(174, 135, 250);font-size: 15px;overflow-wrap: inherit !important;word-break: inherit !important;"></span></span><br  /><br  /><span style="line-height: inherit;color: rgb(128, 128, 128);font-size: 15px;letter-spacing: normal;overflow-wrap: inherit !important;word-break: inherit !important;"># 设置文本放置位置,居中</span><br  /><span style="font-size: 15px;letter-spacing: normal;">draw.text((pos_x_1, <span style="font-size: 15px;line-height: inherit;color: rgb(174, 135, 250);overflow-wrap: inherit !important;word-break: inherit !important;">200</span>), <span style="font-size: 15px;line-height: inherit;color: rgb(238, 220, 112);overflow-wrap: inherit !important;word-break: inherit !important;">'距 离 新 年 还 有'</span>, fill=(<span style="font-size: 15px;line-height: inherit;color: rgb(174, 135, 250);overflow-wrap: inherit !important;word-break: inherit !important;">217</span>, <span style="font-size: 15px;line-height: inherit;color: rgb(174, 135, 250);overflow-wrap: inherit !important;word-break: inherit !important;">217</span>, <span style="font-size: 15px;line-height: inherit;color: rgb(174, 135, 250);overflow-wrap: inherit !important;word-break: inherit !important;">217</span>, <span style="font-size: 15px;line-height: inherit;color: rgb(174, 135, 250);overflow-wrap: inherit !important;word-break: inherit !important;">255</span>), font=font2)</span><br  /><span style="font-size: 15px;letter-spacing: normal;">draw.text((pos_x_2, <span style="font-size: 15px;line-height: inherit;color: rgb(174, 135, 250);overflow-wrap: inherit !important;word-break: inherit !important;">1400</span>), <span style="font-size: 15px;line-height: inherit;color: rgb(238, 220, 112);overflow-wrap: inherit !important;word-break: inherit !important;">'天'</span>, fill=(<span style="font-size: 15px;line-height: inherit;color: rgb(174, 135, 250);overflow-wrap: inherit !important;word-break: inherit !important;">217</span>, <span style="font-size: 15px;line-height: inherit;color: rgb(174, 135, 250);overflow-wrap: inherit !important;word-break: inherit !important;">217</span>, <span style="font-size: 15px;line-height: inherit;color: rgb(174, 135, 250);overflow-wrap: inherit !important;word-break: inherit !important;">217</span>, <span style="font-size: 15px;line-height: inherit;color: rgb(174, 135, 250);overflow-wrap: inherit !important;word-break: inherit !important;">255</span>), font=font2)</span><br  /><span style="font-size: 15px;letter-spacing: normal;">draw.text((pos_x_3, <span style="font-size: 15px;line-height: inherit;color: rgb(174, 135, 250);overflow-wrap: inherit !important;word-break: inherit !important;">1700</span>), wenhou[i<span style="font-size: 15px;line-height: inherit;color: rgb(174, 135, 250);overflow-wrap: inherit !important;word-break: inherit !important;">-1</span>], fill=im_color[i<span style="font-size: 15px;line-height: inherit;color: rgb(174, 135, 250);overflow-wrap: inherit !important;word-break: inherit !important;">-1</span>], font=font3)</span><br  /><br  /><span style="line-height: inherit;color: rgb(128, 128, 128);font-size: 15px;letter-spacing: normal;overflow-wrap: inherit !important;word-break: inherit !important;"># 设置变化的文本属性</span><br  /><span style="font-size: 15px;letter-spacing: normal;">txtSize_4 = draw.textsize(str(i), font1)</span><br  /><span style="letter-spacing: normal;"><span style="font-size: 15px;">pos_x_4 = (<span style="font-size: 15px;line-height: inherit;color: rgb(174, 135, 250);overflow-wrap: inherit !important;word-break: inherit !important;">1000</span> - txtSize_4[<span style="font-size: 15px;line-height: inherit;color: rgb(174, 135, 250);overflow-wrap: inherit !important;word-break: inherit !important;">0</span>]) / <span style="font-size: 15px;line-height: inherit;color: rgb(174, 135, 250);overflow-wrap: inherit !important;word-break: inherit !important;">2</span></span><span style="line-height: inherit;color: rgb(174, 135, 250);font-size: 15px;overflow-wrap: inherit !important;word-break: inherit !important;"></span></span><br  /><span style="font-size: 15px;letter-spacing: normal;">draw.text((pos_x_4, <span style="font-size: 15px;line-height: inherit;color: rgb(174, 135, 250);overflow-wrap: inherit !important;word-break: inherit !important;">600</span>), str(i), fill=(<span style="font-size: 15px;line-height: inherit;color: rgb(174, 135, 250);overflow-wrap: inherit !important;word-break: inherit !important;">255</span>, <span style="font-size: 15px;line-height: inherit;color: rgb(174, 135, 250);overflow-wrap: inherit !important;word-break: inherit !important;">192</span>, <span style="font-size: 15px;line-height: inherit;color: rgb(174, 135, 250);overflow-wrap: inherit !important;word-break: inherit !important;">0</span>, <span style="font-size: 15px;line-height: inherit;color: rgb(174, 135, 250);overflow-wrap: inherit !important;word-break: inherit !important;">255</span>), font=font1)</span><span style="font-size: 15px;letter-spacing: normal;"></span><br  /></section>
<section style="margin-left: 16px;margin-right: 16px;"><br  /></section><section style="margin-left: 16px;margin-right: 16px;"><br  /></section><pre style="color: rgb(62, 62, 62);font-size: 16px;"><section style="margin-right: 16px;margin-left: 16px;"><span style="background-color: rgb(255, 169, 0);color: rgb(255, 255, 255);font-family: Optima-Regular, PingFangTC-light;text-align: left;font-size: 20px;letter-spacing: 1px;">005.</span><br  /></section><p style="margin-left: 16px;margin-right: 16px;"><span style="font-size: 20px;font-family: Optima-Regular, PingFangTC-light;letter-spacing: 1px;">保存图像到本地</span></p>

<section style="margin-left: 16px;margin-right: 16px;"><span style="font-size: 15px;letter-spacing: 1px;">保存图像到当前目录中</span><br  /></section><section style="margin-left: 16px;margin-right: 16px;"><span style="font-size: 15px;letter-spacing: 1px;">命名为:</span><span style="font-size: 15px;background-color: rgb(214, 214, 214);letter-spacing: 1px;">dayx.png</span><br  /></section><section style="margin-left: 16px;margin-right: 16px;"><br  /></section>
<section style="line-height: 18px;font-size: 14px;letter-spacing: 0px;font-family: Consolas, Inconsolata, Courier, monospace;border-radius: 0px;color: rgb(169, 183, 198);background: rgb(40, 43, 46);padding: 0.5em;margin-left: 16px;margin-right: 16px;overflow-wrap: normal !important;word-break: normal !important;overflow: auto !important;display: -webkit-box !important;"><span style="line-height: inherit;color: rgb(128, 128, 128);font-size: 15px;letter-spacing: normal;overflow-wrap: inherit !important;word-break: inherit !important;"># 保存图像</span><br  /><span style="font-size: 15px;letter-spacing: normal;">filename = <span style="font-size: 15px;line-height: inherit;color: rgb(238, 220, 112);overflow-wrap: inherit !important;word-break: inherit !important;">'day'</span> + str(i) + <span style="font-size: 15px;line-height: inherit;color: rgb(238, 220, 112);overflow-wrap: inherit !important;word-break: inherit !important;">'.png'</span></span><span style="line-height: inherit;color: rgb(238, 220, 112);font-size: 15px;letter-spacing: normal;overflow-wrap: inherit !important;word-break: inherit !important;"></span><br  /><span style="font-size: 15px;letter-spacing: normal;">im.save(filename)</span><span style="font-size: 15px;letter-spacing: normal;"></span><br  /></section>
<section style="margin-left: 16px;margin-right: 16px;"><br  /></section><section style="margin-left: 16px;margin-right: 16px;"><br  /></section><pre style="color: rgb(62, 62, 62);font-size: 16px;"><section style="margin-right: 16px;margin-left: 16px;"><span style="background-color: rgb(255, 169, 0);color: rgb(255, 255, 255);font-family: Optima-Regular, PingFangTC-light;text-align: left;font-size: 20px;letter-spacing: 1px;">006.</span><br  /></section><p style="margin-right: 16px;margin-left: 16px;"><span style="font-size: 20px;font-family: Optima-Regular, PingFangTC-light;letter-spacing: 1px;">我是总结</span></p>

参考了大佬的部分代码,
利用pillow关于图像处理的模块,

加入了一些新的设计元素,
制作了新一版本的新年倒计时海报。


回复“新年快乐”
可获取完整代码的Github地址
<section style="margin-right: 16px;margin-left: 16px;white-space: normal;letter-spacing: 0.5px;line-height: 1.5em;text-align: center;"><br  /></section><section style="margin-right: 16px;margin-left: 16px;white-space: normal;letter-spacing: 0.5px;line-height: 1.5em;text-align: center;"><br  /></section>

本篇文章来源于: 菜鸟学Python

本文为原创文章,版权归所有,欢迎分享本文,转载请保留出处!

知行编程网
知行编程网 关注:1    粉丝:1
这个人很懒,什么都没写

你可能也喜欢

热评文章

发表评论

表情 格式 链接 私密 签到
扫一扫二维码分享