-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpic_format_convert.py
More file actions
34 lines (27 loc) · 945 Bytes
/
pic_format_convert.py
File metadata and controls
34 lines (27 loc) · 945 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# -*- coding: utf-8 -*-
# @Time : 2021/7/19 22:54
# @Author : beyoung
# @Email : linbeyoung@stu.pku.edu.cn
# @File : format_convert.py
import os
from PIL import Image
def gif2jpg(gif_file, output):
img = Image.open(gif_file)
# print(img.mode, img.format) # P 和 GIF
img = img.convert('RGB')
# print(img.mode, img.format)
img.save(output)
# img2 = Image.open('223.jpg')
# print(img2.format) # JPEG
return
PIC_SET = ['.gif', '.tif', '.jpg', '.jepg']
path = '/Users/Beyoung/Desktop/Projects/ER/txtpic.part01/txtpic/228_00475'
op_path = path + '_jpg'
if not os.path.exists(op_path):
os.mkdir(op_path)
files = os.listdir(path)
for file in files:
if os.path.splitext(os.path.join(path, file))[-1].lower() in PIC_SET:
# if file.startswith('.gif'):
print(os.path.join(path, file)[:-4] + '.jpg')
gif2jpg(os.path.join(path, file), os.path.join(op_path, file)[:-4] + '.jpg')