当前位置:网站首页>PIL's image tool image reduction and splicing.
PIL's image tool image reduction and splicing.
2022-07-05 07:36:00 【33 year old Java enthusiast】
Due to the research, Taobao teachers need to splice and cut detailed pictures
So use PIL Wrote a little program , If you need it, you can copy it .
Things are things that people use .
Get a friend to order a collection if you are useful
# -*- codeing = utf-8 -*-
# @Time : 2021/5/12
# @Author : ckw
# @File : 1.py
# @Software :PyCharm
from PIL import Image
import os
import glob
def pinjie(dirpath):
paths = glob.glob(dirpath + "/*.jpg")
paths.sort()
files = paths
width = 750
x = width
y = 0
for path_base in files:
img = Image.open(path_base)
size = img.size
if size[0] <= width:
pass
else:
size[0] > width
hight = int(width / (size[0] / size[1]))
img = img.resize((width, hight))
y += img.size[1]
img.close()
new_img = Image.new('RGB', (x, y), (255, 255, 255)) # Get the splice length
x = 0
y = 0
for path_base in files:
img = Image.open(path_base)
size = img.size
x = 0
if size[0] <= width:
new_img.paste(img, (x, y + 1))
y = y + img.size[1]
else:
size[0] > width
hight = int(width / (size[0] / size[1]))
img_1 = img.resize((width, hight))
new_img.paste(img_1, (x, y + 1))
y = y + img_1.size[1]
img.close()
# dirpath = os.path.dirname(dirpath)
usefilepath = dirpath + '\\' + ' Splicing synthesis '
if os.path.exists(usefilepath):
print(' file already exist ')
else:
os.mkdir(usefilepath)
print(' Generate file directory ')
path_m = usefilepath + '\\' + '1.jpg'
new_img.save(path_m)
new_img.close
print(' Picture splicing is completed ')
def qiepian(path, h):
if os.path.exists(path):
new_img = Image.open(path)
x1 = 0
y1 = 0
x2 = 0
y2 = 0
n = 1
v = -(-new_img.size[1] // h)
y2 = h
usefilepath = os.path.dirname(path) + '\\' + ' Slice segmentation '
if os.path.exists(usefilepath):
print(' file already exist ')
else:
os.mkdir(usefilepath)
print(' Generate file directory ')
for n in range(v):
x2 = new_img.size[0]
if y2 > new_img.size[1]:
y2 = new_img.size[1]
box = (x1, y1, x2, y2)
img = new_img.crop(box)
y1 = y2 + 1
y2 = y2 + 1 + h
path_3 = usefilepath + '\\' + '%d.jpg' % n
img.save(path_3)
img = 0
n += 1
print(' Slice successfully , Generate the file ')
else:
print(' No documents found , Please re-enter ')
def chongsu(dirpath,width,hight):
paths = glob.glob(dirpath + "/*.jpg")
paths.sort()
files = paths
# width = 750
x = width
y = 0
for path_base in files:
img = Image.open(path_base)
size = img.size
if size[0] <= width:
pass
else:
size[0] > width
hight = int(width / (size[0] / size[1]))
img = img.resize((width, hight))
y += img.size[1]
img.close()
new_img = Image.new('RGB', (x, y), (255, 255, 255)) # Get the splice length
x = 0
y = 0
for path_base in files:
img = Image.open(path_base)
size = img.size
x = 0
if size[0] <= width:
new_img.paste(img, (x, y + 1))
y = y + img.size[1]
else:
size[0] > width
hight = int(width / (size[0] / size[1]))
img_1 = img.resize((width, hight))
new_img.paste(img_1, (x, y + 1))
y = y + img_1.size[1]
img.close()
x1 = 0
y1 = 0
x2 = 0
y2 = 0
n = 1
h=hight
v = -(-new_img.size[1] // h)
y2 = h
usefilepath = os.path.dirname(dirpath) + '\\' + ' Slice segmentation '
if os.path.exists(usefilepath):
print(' file already exist ')
else:
os.mkdir(usefilepath)
print(' Generate file directory ')
for n in range(v):
x2 = new_img.size[0]
if y2 > new_img.size[1]:
y2 = new_img.size[1]
box = (x1, y1, x2, y2)
img = new_img.crop(box)
y1 = y2 + 1
y2 = y2 + 1 + h
path_3 = usefilepath + '\\' + '%d.jpg' % n
img.save(path_3)
img = 0
n += 1
print(' Slice successfully , Generate the file ')
def zypinjie(dirpath,width):
paths = glob.glob(dirpath + "/*.jpg")
paths.sort()
files = paths
x = width
y = 0
for path_base in files:
img = Image.open(path_base)
size = img.size
if size[0] <= width:
pass
else:
size[0] > width
hight = int(width / (size[0] / size[1]))
img = img.resize((width, hight))
y += img.size[1]
img.close()
new_img = Image.new('RGB', (x, y), (255, 255, 255)) # Get the splice length
x = 0
y = 0
for path_base in files:
img = Image.open(path_base)
size = img.size
x = 0
if size[0] <= width:
new_img.paste(img, (x, y + 1))
y = y + img.size[1]
else:
size[0] > width
hight = int(width / (size[0] / size[1]))
img_1 = img.resize((width, hight))
new_img.paste(img_1, (x, y + 1))
y = y + img_1.size[1]
img.close()
# dirpath = os.path.dirname(dirpath)
usefilepath = dirpath + '\\' + ' Splicing synthesis '
if os.path.exists(usefilepath):
print(' file already exist ')
else:
os.mkdir(usefilepath)
print(' Generate file directory ')
path_m = usefilepath + '\\' + '1.jpg'
new_img.save(path_m)
new_img.close
print(' Picture splicing is completed ')
def main():
print(' The main menu :\n 1. File slice \n\n 2. Picture splicing \n\n 3. Reshape cutting \n\n 4. Free stitching \n\n 5. Shut down the program \n\n')
insel = input(' Please enter the required function :')
if insel == '1':
jpgpath = input(' Please enter the path of the image you want to slice :')
if jpgpath=='':
main()
hight = int(input(' Enter the image height you want :'))
if hight=='':
main()
qiepian(jpgpath, hight)
main()
elif insel == '2':
dirpath = input(' Please enter the folder location to be spliced :')
if dirpath=='':
main()
pinjie(dirpath)
main()
elif insel == '3':
dirpath = input(' Please enter the folder location to be spliced :')
width = int(input(' Please enter the required file width :'))
hight = int(input(' Please enter the height of the file to be segmented :'))
if dirpath=='':
main()
if width=='':
main()
if width=='':
main()
chongsu(dirpath,width,hight)
main()
elif insel == '4':
dirpath = input(' Please enter the folder location to be spliced :')
width = int(input(' Please enter the required file width :'))
if dirpath=='':
main()
if width=='':
main()
zypinjie(dirpath,width)
main()
elif insel == '5':
quit()
if __name__ == '__main__':
main()
边栏推荐
- NSIS search folder
- Machine learning Seaborn visualization
- Word import literature -mendeley
- NPM and package common commands
- Latex notes
- Clickhouse database installation deployment and remote IP access
- 行测--资料分析--fb--高照老师
- Hdu1231 maximum continuous subsequence (divide and conquer or dynamic gauge or double pointer)
- How to modify the file path of Jupiter notebook under miniconda
- 2022 PMP project management examination agile knowledge points (7)
猜你喜欢

Pagoda create multiple sites with one server
![[idea] efficient plug-in save actions to improve your work efficiency](/img/6e/49037333964865d9900ddf5698f7e6.jpg)
[idea] efficient plug-in save actions to improve your work efficiency

Using GEE plug-in in QGIS

借助 Navicat for MySQL 软件 把 不同或者相同数据库链接中的某数据库表数据 复制到 另一个数据库表中

Set theory of Discrete Mathematics (I)
![[neo4j] common operations of neo4j cypher and py2neo](/img/ff/8576d5784fcfa474eb1c0acd8a8065.jpg)
[neo4j] common operations of neo4j cypher and py2neo

CADD课程学习(6)-- 获得已有的虚拟化合物库(Drugbank、ZINC)

Ugnx12.0 initialization crash, initialization error (-15)

Today, share the wonderful and beautiful theme of idea + website address

Package ‘*****‘ has no installation candidate
随机推荐
611. Number of effective triangles
I implement queue with C I
Graduation thesis project local deployment practice
Altimeter data knowledge point 2
Ue5 hot update - remote server automatic download and version detection (simplehotupdate)
纯碱是做什么的?
Shadowless cloud desktop - online computer
Apple input method optimization
deepin 20 kivy unable to get a window, abort
I 用c l 栈与队列的相互实现
golang定时器使用踩的坑:定时器每天执行一次
Opendrive ramp
使用go语言读取txt文件写入excel中
Rough notes of C language (1)
Daily Practice:Codeforces Round #794 (Div. 2)(A~D)
Jenkins reported an error. Illegal character: '\ufeff'. Class, interface or enum are required
Typecho adds Baidu collection (automatic API submission plug-in and crawler protocol)
Rough notes of C language (2) -- constants
Basic series of SHEL script (I) variables
Play with grpc - go deep into concepts and principles