from PIL import Image
import os.path
import glob
def convertjpg(jpgfile,outdir,width=1280,height=1024):
img=Image.open(jpgfile)
new_img=img.resize((width,height),Image.BILINEAR)
new_img.save(os.path.join(outdir,os.path.basename(jpgfile)))
for jpgfile in glob.glob("/home/yo/caffe/myproject/zte/test_set/*.jpg"):
convertjpg(jpgfile,"/home/youname/mycode/cv/set")uname
import os.path
import glob
def convertjpg(jpgfile,outdir,width=1280,height=1024):
img=Image.open(jpgfile)
new_img=img.resize((width,height),Image.BILINEAR)
new_img.save(os.path.join(outdir,os.path.basename(jpgfile)))
for jpgfile in glob.glob("/home/yo/caffe/myproject/zte/test_set/*.jpg"):
convertjpg(jpgfile,"/home/youname/mycode/cv/set")uname
本文介绍了一种使用Python的PIL库来批量调整JPG图片尺寸的方法。通过定义一个函数convertjpg,可以将指定目录下的所有.jpg文件按设定的宽度和高度进行缩放,并保存到新的目录中。
349

被折叠的 条评论
为什么被折叠?



