Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/JackHCC/SlideShow
python照片墙设计,将爬虫获取的照片布局成爱心形状~( Python photo wall design, layout photos taken by reptiles into a love shape~)
https://github.com/JackHCC/SlideShow
mini-program pil python
Last synced: 4 days ago
JSON representation
python照片墙设计,将爬虫获取的照片布局成爱心形状~( Python photo wall design, layout photos taken by reptiles into a love shape~)
- Host: GitHub
- URL: https://github.com/JackHCC/SlideShow
- Owner: JackHCC
- Created: 2019-04-25T10:42:31.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-04-25T12:25:15.000Z (over 5 years ago)
- Last Synced: 2024-08-02T00:21:43.704Z (3 months ago)
- Topics: mini-program, pil, python
- Language: Python
- Homepage:
- Size: 436 KB
- Stars: 12
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# python照片墙设计
### 代码规划:
+ 将爬虫爬取的图片进行处理,减小尺寸
+ 将处理好的图片进行照片墙设计
### 图片处理ImageSolve.py:批量处理
+ 导入库:PIL:图像处理;glob
```
from PIL import Image
import os.path
import glob
```
+ 定义ReSize函数:
```
#由于爬虫获取的照片尺寸太大,我们更改爬虫获取的照片尺寸大小
def Resize(file, outdir, width, height):
imgFile = Image.open(file)
try:
newImage = imgFile.resize((width, height), Image.BILINEAR) #更改尺寸
newImage.save(os.path.join(outdir, os.path.basename(file))) #输出保存图片
except Exception as e:
print(e)
```
+ 处理后照片的存储
```
for file in glob.glob("res\\*.jpg"): # 图片所在的目录
Resize(file, "new", 100, 100) # 新图片存放的目录
```
### 照片墙展示
+ 导入库
```
import sys
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import *
```
+ Qt窗口基本创建
```
app = QApplication(sys.argv)win = QWidget()
win.resize(760, 540)
win.move(0, 0)
layout=QGridLayout(win)positionSet()
win.setWindowTitle('GUI')
win.show()
```
+ 背景图设置
```
b=QLabel(win)
b.setPixmap(QPixmap("bg.jpg"))
b.setGeometry(0,0,820,640)
```
+ 布局函数
```
def positionSet():
```
### 结果展示
![show](result.jpg)