Skip to content

Commit 3e2b36e

Browse files
committed
add code
1 parent de6a5cc commit 3e2b36e

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed
8.88 MB
Binary file not shown.

doudou/2021-10-28-pillow/app.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
from PIL import Image, ImageFilter, ImageEnhance, ImageDraw, ImageFont
2+
3+
img = Image.open('cat.jpg')
4+
print(F'图片大小为 {img.format}, 格式为 {img.size}, 模式为 {img.mode}')
5+
6+
# img.show()
7+
8+
# img.save("cat.png")
9+
10+
# 剪裁
11+
#point = (1500, 800, 3000, 2300)
12+
#img_crop = img.crop(point)
13+
#img_crop.show()
14+
15+
# 覆盖
16+
#img.paste(img_crop, (0, 0), None)
17+
#img.show()
18+
19+
# 缩略图
20+
# thumb_size = (345, 345)
21+
# img.thumbnail(thumb_size)
22+
# img.show()
23+
24+
# 旋转
25+
# img_rotate = img.transpose(Image.ROTATE_90)
26+
# img_rotate.show()
27+
28+
# 滤镜
29+
# 高斯模糊
30+
# img_gaussianblur = img.filter(ImageFilter.GaussianBlur(30))
31+
# img_gaussianblur.show()
32+
33+
# 轮廓
34+
# img_contour = img.filter(ImageFilter.CONTOUR)
35+
# img_contour.show()
36+
37+
# 增强
38+
#color = ImageEnhance.Color(img)
39+
#img_color = color.enhance(1.5)
40+
#img_color.show()
41+
42+
# draw = ImageDraw.Draw(img)
43+
44+
# 画线
45+
# draw.line((0, 0) + img.size, fill=20, width=3)
46+
# draw.line((0, img.size[1], img.size[0], 0), fill=200, width=3)
47+
48+
# 写字
49+
# font = ImageFont.truetype('AliPuHui-Bold.ttf', 200)
50+
# text = 'This is a cat!'
51+
# drawing text size
52+
# draw.text((450, 450), text, font=font, fill='pink', align="left")
53+
# img.show()

doudou/2021-10-28-pillow/cat.jpg

956 KB
Loading

doudou/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Python技术 公众号文章代码库
88

99
## 实例代码
1010

11+
[一行代码搞定的事还用个锤子的 PS 啊](https://github.com/JustDoPython/python-examples/tree/master/doudou/2021-10-28-pillow)
12+
1113
[涨姿势|看我如何用 Python 哄女朋友开心](https://github.com/JustDoPython/python-examples/tree/master/doudou/2021-10-21-pig)
1214

1315
[付费?不存在的,20 行代码将电子书转换为有声小说](https://github.com/JustDoPython/python-examples/tree/master/doudou/2021-09-29-pdf-to-mp3)

0 commit comments

Comments
 (0)