python webp圖片格式轉(zhuǎn)化的方法
本文實(shí)例為大家分享了python webp圖片格式轉(zhuǎn)化的具體代碼,供大家參考,具體內(nèi)容如下
1、將本地的webp圖片轉(zhuǎn)換為jpg2、將下載的webp格式圖片直接保存為jpg
代碼如下:
1、將本地的webp圖片轉(zhuǎn)換為jpg
from PIL import Image filename = ’xxxxxxxxxx.webp’im = Image.open(filename)if im.mode == 'RGBA': im.load() # required for png.split() background = Image.new('RGB', im.size, (255, 255, 255)) background.paste(im, mask=im.split()[3])save_name = filename.replace(’webp’, ’jpg’)im.save(’{}’.format(save_name), ’JPEG’)
2、將下載的webp格式圖片直接保存為jpg
from io import BytesIOfrom PIL import Imageimport requests url = ’http:xxxxx.JPG’ # 需要下載的圖片地址headers = {} # 請求頭,按需添加 resp = requests.get(url, headers=headers)byte_stream = BytesIO(resp.content)im = Image.open(byte_stream) # im.show()if im.mode == 'RGBA': im.load() # required for png.split() background = Image.new('RGB', im.size, (255, 255, 255)) background.paste(im, mask=im.split()[3]) im.save(’xxx.jpg’, ’JPEG’)
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. ASP基礎(chǔ)知識Command對象講解2. ASP.NET MVC通過勾選checkbox更改select的內(nèi)容3. JavaScrip簡單數(shù)據(jù)類型隱式轉(zhuǎn)換的實(shí)現(xiàn)4. 解決ajax請求后臺,有時(shí)收不到返回值的問題5. jsp+mysql實(shí)現(xiàn)網(wǎng)頁的分頁查詢6. javascript xml xsl取值及數(shù)據(jù)修改第1/2頁7. ASP中實(shí)現(xiàn)字符部位類似.NET里String對象的PadLeft和PadRight函數(shù)8. XHTML 1.0:標(biāo)記新的開端9. JSP 中request與response的用法詳解10. asp知識整理筆記4(問答模式)
