国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Python編程圖形庫之Pillow使用方法講解

2020-02-16 00:21:59
字體:
來源:轉載
供稿:網友

PIL vs Pillow

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

Pillow的目標

推動和促進PIL的發展是Pillow的目標,主要通過如下的方式來進行

結合Travis CI和AppVeyor進行持續集成測試 活用github進行開發 結合Python Package Index進行例行發布

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

安裝

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

liumiaocn:~ liumiao$ pip install pillowCollecting 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: pillowSuccessfully installed pillow-5.1.0liumiaocn:~ liumiao$

安裝確認

liumiaocn:~ liumiao$ pip show pillowName: PillowVersion: 5.1.0Summary: Python Imaging Library (Fork)Home-page: https://python-pillow.orgAuthor: Alex Clark (Fork Author)Author-email: aclark@aclark.netLicense: Standard PIL LicenseLocation: /usr/local/lib/python2.7/site-packagesRequires: Required-by: liumiaocn:~ liumiao$ 

使用

圖形庫有很多實用的功能,這里列舉幾個進行簡單演示。

ImageGrab.grab()

使用這個方法可以實現抓屏:

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

因為代碼中使用了image.show()進行了顯示,執行之后可以直接看到顯示,同時也能確認到/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.bmpliumiaocn:tmp liumiao$

濾鏡

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

liumiaocn:tmp liumiao$ cat filter-contour.py #!/usr/local/bin/pythonfrom PIL import ImageFilter, Imagesrc_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$            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 武定县| 雷州市| 龙川县| 会同县| 安阳市| 临邑县| 肇州县| 甘德县| 额尔古纳市| 修武县| 松滋市| 南乐县| 新乡市| 盐城市| 六枝特区| 改则县| 湖北省| 疏附县| 鹤山市| 龙胜| 莆田市| 津南区| 隆安县| 隆化县| 广州市| 定边县| 新河县| 京山县| 红河县| 靖边县| 江华| 格尔木市| 称多县| 贵港市| 耒阳市| 诸暨市| 大足县| 高安市| 南华县| 泽库县| 砚山县|