请帮忙看下是那是出错
加上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) 本帖最后由 陶远航 于 2022-8-31 14:45 编辑
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)
试试 报的什么错啊?麻烦发出来呗。不知道报什么错怎么给你解决。
是不是缩进不对,瞅着像是缩进的问题,else和if没对齐,麻烦发代码用论坛发代码的发。就是<>这个标志。
发出来是这样
z=x+y
方便大家看和分析 解决了吗 else往里缩了几格。
在python里,缩进的要求很严,一旦多一个空格或者少一个空格都不行。但正是python缩进严格的特点,才避免了悬挂else等问题。 陶远航 发表于 2022-8-31 14:23
你的程序也有点问题,我找到问题所在了,是空格与TAB
页:
[1]