|
2鱼币
加上else后就出错了
pic_dir = os.getcwd() #
print (pic_dir)
for filename in os.listdir (path = pic_dir):
if filename.split('.')[-1] in ['png', 'PNG', 'jpg', 'JPG', 'eps', 'EPS']:
print (filename)
path2 = (pic_dir + '/' + filename)
##print (path2)
image = Image.open (path2)
image = image.convert('RGB')
pci = image.getpixel((1, 1))
w, h = image.size
w1, h1 = (64,64)
aa = 5
print (aa)
if w > 64 or h > 64:
background = Image.new('RGB', size=(max(w, h), max(w, h)), color = pci)
length = int(abs(w - h) // 2)
box = (length, 0) if w < h else (0, length)
box = (length, 0) if w < h else (0, length)
background.paste(image, box)
image_data = background.resize ((64,64))
ame = os.path.split(path2)
savefp = os.path.join(path,filename)
image_data.save(savefp)
else:
print ('7')
path, filename = os.path.split(path2)
savefp = os.path.join(path,filename) #直接代替原文件
image_data.save(savefp)
import os
pic_dir = os.getcwd() #
print (pic_dir)
for filename in os.listdir (path = pic_dir):
if filename.split('.')[-1] in ['png', 'PNG', 'jpg', 'JPG', 'eps', 'EPS']:
print (filename)
path2 = (pic_dir + '/' + filename)
##print (path2)
image = Image.open (path2)
image = image.convert('RGB')
pci = image.getpixel((1, 1))
w, h = image.size
w1, h1 = (64,64)
aa = 5
print (aa)
if w > 64 or h > 64:
background = Image.new('RGB', size=(max(w, h), max(w, h)), color = pci)
length = int(abs(w - h) // 2)
box = (length, 0) if w < h else (0, length)
box = (length, 0) if w < h else (0, length)
background.paste(image, box)
image_data = background.resize ((64,64))
ame = os.path.split(path2)
savefp = os.path.join(path,filename)
image_data.save(savefp)
else:
print ('7')
path, filename = os.path.split(path2)
savefp = os.path.join(path,filename) #直接代替原文件
image_data.save(savefp)
|
|