聯系我們 - 廣告服務 - 聯系電話:
您的當前位置: > 關注 > > 正文

世界簡訊:不會跑代碼怎么辦?python3的代碼幫你解決

來源:CSDN 時間:2023-04-17 09:45:04


(資料圖片僅供參考)

文章目錄

1. 按2. 代碼

1. 按

很多時候我們需要用到ico格式的圖片,網上看好的圖片又沒有ico格式的,于是自己就寫了段python3的代碼用于解決轉換圖片格式的問題。不會跑代碼怎么辦?我發現也有一個專門將圖片轉成ico的網站:http://www.bitbug.net/

2. 代碼

# -*- coding: utf-8 -*-"""@Python:Python 3.7.4@author = Coco56@date = 2019-09-25@個人博客 : 請百度搜索“Coco56”"""import osfrom PIL import Imageclass Picture:    def __init__(self):        self.ext = ["jpg","jpeg","png"]        self.files = os.listdir(".")    def handle_picture(self, file):        img = Image.open(file).convert("RGBA")        if img.size != (128, 128):  # 判斷圖片大小,統一改為 128*128            # 修改圖片尺寸            img.thumbnail((128, 128))        img.save(file.split(".")[0]+".ico")    def run(self):        cnt=1        for file in self.files:            if file.split(".")[-1] in self.ext and not os.path.exists(file.split(".")[0]+".ico"):                print(cnt, file)                self.handle_picture(file)                cnt+=1if __name__ == "__main__":    ins = Picture()    ins.run()

責任編輯:

標簽:

相關推薦:

精彩放送:

新聞聚焦
Top 岛国精品在线