# --*-- coding: utf-8 -*-
from PIL import Image
import os
try:
    ml=u"只缩小图片大小"
    os.mkdir(ml)
except Exception as e:
    pass
pics=[pic for pic in os.listdir(".") if pic.lower().endswith("png") or pic.lower().endswith("jpg") or pic.lower().endswith("gif") or pic.lower().endswith("jpeg")]
for f in pics:
    try:
        im=Image.open(f)
        im=im.convert('RGB')
    
        newName=f.replace("png","jpg")
        im.save("%s/%s" % (ml,newName),quality=60)
    except Exception as e:
        pass





# --*-- coding: utf-8 -*-
from PIL import Image
import os
try:
    ml=u"图片尺寸改为1000"
    os.mkdir(ml)
except Exception as e:
    pass
pics=[pic for pic in os.listdir(".") if pic.lower().endswith("png") or pic.lower().endswith("jpg") or pic.lower().endswith("gif") or pic.lower().endswith("jpeg")]

for f in pics:
    try:
        im=Image.open(f)
        im=im.convert('RGB')
        w,h=im.size

        if w>h:
            new_w=1000
            new_h=int(h/(w/1000))
        else:
            new_h=1000
            new_w=int(w/(h/1000))
    
        im=im.resize(size=(new_w,new_h))
        newName=f.replace("png","jpg")
        im.save("%s/%s" % (ml,newName))
    except Exception as e:
        pass

 

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注