欧美成人午夜免费全部完,亚洲午夜福利精品久久,а√最新版在线天堂,另类亚洲综合区图片小说区,亚洲欧美日韩精品色xxx

扣丁學(xué)堂Python培訓(xùn)詳解Python編程圖形庫之Pillow使用方法

2019-08-16 10:19:17 5320瀏覽

本篇文章扣丁學(xué)堂Python培訓(xùn)小編就為大家分享一篇關(guān)于Python編程圖形庫之Pillow使用方法講解,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,對Python開發(fā)技術(shù)感興趣的小伙伴就隨小編來看看吧,希望對小伙伴們有幫助。


扣丁學(xué)堂Python培訓(xùn)詳解Python編程圖形庫之Pillow使用方法


PIL vs Pillow:


PIL: Python Imaging Library,是python的圖像處理庫。由于PIL不兼容setuptools,再加上更新緩慢等因素,Alex Clark等一些社區(qū)好心人還是希望能夠繼續(xù)支持PIL,所以fork了PIL,這就是Pillow的緣起。



Pillow的目標(biāo):


推動和促進(jìn)PIL的發(fā)展是Pillow的目標(biāo),主要通過如下的方式來進(jìn)行

結(jié)合Travis CI和AppVeyor進(jìn)行持續(xù)集成測試

活用github進(jìn)行開發(fā)

結(jié)合Python Package Index進(jìn)行例行發(fā)布

其實(shí)可以看出,所做的改善就是在CI和CD,改善用戶感知,定期/快速地與使用者進(jìn)行溝通和交流,是pillow獲得好感的一個重要因素。


安裝


安裝可以通過pip,只需要執(zhí)行pip install pillow即可

liumiaocn:~ liumiao$ pip install pillow
Collecting pillow
 Downloading https://files.pythonhosted.org/packages/df/aa/a25f211a4686f363d8ca5a1752c43a8f42459e70af13e20713d3e636f0af/Pillow-5.1.0-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (3.6MB)
  100% |████████████████████████████████| 3.6MB 157kB/s 
Installing collected packages: pillow
Successfully installed pillow-5.1.0
liumiaocn:~ liumiao$


安裝確認(rèn)


liumiaocn:~ liumiao$ pip show pillow
Name: Pillow
Version: 5.1.0
Summary: Python Imaging Library (Fork)
Home-page: https://python-pillow.org
Author: Alex Clark (Fork Author)
Author-email: aclark@aclark.net
License: Standard PIL License
Location: /usr/local/lib/python2.7/site-packages
Requires: 
Required-by: 
liumiaocn:~ liumiao$ 


使用


圖形庫有很多實(shí)用的功能,這里列舉幾個進(jìn)行簡單演示。


ImageGrab.grab()


使用這個方法可以實(shí)現(xiàn)抓屏:


liumiaocn:tmp liumiao$ cat grab.python 
#!/usr/local/bin/python
from PIL import ImageGrab
#get current screen copy
image = ImageGrab.grab()
#display image size
print("Current screen shot size :",image.size)
#display image mode
print("Screen shot picture mode :", image.mode)
#save picture to /tmp/screen-grab-1.bmp
image.save('/tmp/screen-grab-1.bmp')
#show picture
image.show()
liumiaocn:tmp liumiao$


因?yàn)榇a中使用了image.show()進(jìn)行了顯示,執(zhí)行之后可以直接看到顯示,同時(shí)也能確認(rèn)到/tmp下所生成的文件


liumiaocn:tmp liumiao$ python grab.python 
('Current screen shot size :', (2880, 1800))
('Screen shot picture mode :', 'RGBA')
liumiaocn:tmp liumiao$ ls -l /tmp/screen-grab-1.bmp
-rw-r--r-- 1 liumiao wheel 20736054 Jun 23 05:41 /tmp/screen-grab-1.bmp
liumiaocn:tmp liumiao$

Python視頻教程


濾鏡


PIL中的ImageFilter支持近十種濾鏡, 比如對剛剛抓取的圖片使用CONTOUR濾鏡


liumiaocn:tmp liumiao$ cat filter-contour.py 
#!/usr/local/bin/python
from PIL import ImageFilter, Image
src_image = Image.open('/tmp/screen-grab-1.bmp')
print("begin to filter the pic")
dst_image = src_image.filter(ImageFilter.CONTOUR)
print("picture through filter")
dst_image.show()
liumiaocn:tmp liumiao$


執(zhí)行之后可以得到如下圖片:


扣丁學(xué)堂Python在線學(xué)習(xí)


旋轉(zhuǎn)


使用rotate即可對圖片進(jìn)行旋轉(zhuǎn)操作:


liumiaocn:tmp liumiao$ cat rotate.py 
#!/usr/local/bin/python
from PIL import Image
src_image = Image.open('/tmp/screen-grab-1.bmp')
print("begin to rotate the pic")
dst_image = src_image.rotate(90)
print("picture after rotating")
dst_image.show()
liumiaocn:tmp liumiao$


執(zhí)行之后,即可確認(rèn):


扣丁學(xué)堂Python基礎(chǔ)教程


Pillow功能非常之多,而且使用也很方便,比如resize對尺寸進(jìn)行調(diào)節(jié),還可以添加文字等等常見的圖形處理操作,這里就不再一一介紹了。


想要了解更多關(guān)于Python和人工智能方面內(nèi)容的小伙伴,請關(guān)注扣丁學(xué)堂Python培訓(xùn)官網(wǎng)、微信等平臺,扣丁學(xué)堂IT職業(yè)在線學(xué)習(xí)教育平臺為您提供權(quán)威的Python開發(fā)環(huán)境搭建視頻,Python培訓(xùn)后的前景無限,行業(yè)薪資和未來的發(fā)展會越來越好的,扣丁學(xué)堂老師精心推出的Python視頻教程定能讓你快速掌握Python從入門到精通開發(fā)實(shí)戰(zhàn)技能??鄱W(xué)堂Python技術(shù)交流群:279521237。


扣丁學(xué)堂微信公眾號                          Python全棧開發(fā)爬蟲人工智能機(jī)器學(xué)習(xí)數(shù)據(jù)分析免費(fèi)公開課直播間


      【關(guān)注微信公眾號獲取更多學(xué)習(xí)資料】         【掃碼進(jìn)入Python全棧開發(fā)免費(fèi)公開課】



查看更多關(guān)于"Python開發(fā)資訊"的相關(guān)文章>

標(biāo)簽: Python培訓(xùn) Python視頻教程 Python在線視頻 Python學(xué)習(xí)視頻 Python培訓(xùn)班

熱門專區(qū)

暫無熱門資訊

課程推薦

微信
微博
15311698296

全國免費(fèi)咨詢熱線

郵箱:codingke@1000phone.com

官方群:148715490

北京千鋒互聯(lián)科技有限公司版權(quán)所有   北京市海淀區(qū)寶盛北里西區(qū)28號中關(guān)村智誠科創(chuàng)大廈4層
京ICP備2021002079號-2   Copyright ? 2017 - 2022
返回頂部 返回頂部