# 【Python超實戰】讓你的MAC動態桌布(heif格式)批量匯出成png無損格式 @ 小雨の部 :: 痞客邦 :: **Published by:** [Untitled](https://paragraph.com/@0x9c27e247b7de3d29c76b2f5d1ec500285cd89df0/) **Published on:** 2022-03-01 **URL:** https://paragraph.com/@0x9c27e247b7de3d29c76b2f5d1ec500285cd89df0/python-mac-heif-png ## Content 自從好久以前 [WIN10仿MAC] WinDynamicDesktop 自訂桌面教學 後 感覺桌布非常無聊,還是mac原生動態桌布資源最多 但mac的格式都是heif,根本不支援怎辦? 這時就可以用python套件來匯出成png格式,在使用json建立個別的時間變化參數 環境: macOS 11.4 Anaconda3.8 Python3.8 特別提醒:Windows目前不支援此套件的使用喔 安裝之前,先確認一下有無安裝 Homebrew: https://brew.sh/index_zh-tw 或複製此代碼安裝 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" 接著在macOS的終端機打入以下安裝 conda brew install libffi libheif pip install git+https://github.com/david-poirier-csn/pyheif.git pip install whatimage 如無法安裝就代表git網址變動,請參考pypl https://pypi.org/project/pyheif/ 附上程式碼: import whatimage import pyheif import traceback from PIL import Image def decodeImage(bytesIo): try: fmt = whatimage.identify_image(bytesIo) if fmt in ['heic']: i = pyheif.read_heif(bytesIo) pi = Image.frombytes(mode=i.mode, size=i.size, data=i.data) pi.save('heeh.png', format="png") except: traceback.print_exc() def read_image_file_rb(file_path): with open(file_path, 'rb') as f: file_data = f.read() return file_data if __name__ == "__main__": file_path = input("輸入圖片名稱") print('file_path = ./{}'.format(file_path)) data = read_image_file_rb(file_path) decodeImage(data) ## Publication Information - [Untitled](https://paragraph.com/@0x9c27e247b7de3d29c76b2f5d1ec500285cd89df0/): Publication homepage - [All Posts](https://paragraph.com/@0x9c27e247b7de3d29c76b2f5d1ec500285cd89df0/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@0x9c27e247b7de3d29c76b2f5d1ec500285cd89df0): Subscribe to updates