看世界
 
昨日:篇  今日:篇   总帖:篇   会员:
admin
创始人Lv2   
图片形状划分     
# -*- coding: utf-8 -*-

import os
import os.path
from PIL import Image
import shutil
list1 = []
def get_py(path,list1):
    fileList = os.listdir(path) # 获取path目录下所有文件
    for filename in fileList:
        pathTmp = os.path.join(path,filename) # 获取path与filename组合后的路径
        if os.path.isdir(pathTmp):  # 如果是目录
            get_py(pathTmp,list1) # 则递归查找
        elif filename[-4:] == '.jpg':# 如果不是目录,则比较后缀名
            list1.append(pathTmp)

path = 'z:\\100'

# path = input('请输入路径:').strip()
get_py(path,list1)
print('在%s目录及其子目录下找到%d个jpg文件,分别为:' % ( path,len(list1)))
for filename in list1:
    print(filename)

    img = Image.open(filename)
    w = img.size[0]
    h = img.size[1]
    if w > h:
        path1 = "z:\\new\\1\\"
        shutil.copy(filename, path1)
        # print 'type1:' + str(len(filename))

    elif w == h:
    
        # print '正方形图片'
        path2 = "z:\\new\\2\\"
        shutil.copy(filename, path2)
        # print'type2:' + str(len(filename))



    else :
        # print "竖型图片"

        path3 = "z:\\new\\3\\"
        shutil.copy(filename, path3)



        print'type3:' + str(len(filename))

 0  已被阅读了27次  楼主 2018-10-19 13:15:49
回复列表

回复:图片形状划分

LOOK官方站 联系站长
Powered by Look博客