长沙SEO霜天

  • 首页
  • 其他
  • 经验
  • 赚钱
  • 日记
  • python
  • 术语
别放弃
付费找茬,任何不对的地方,付费50。
  1. 首页
  2. 其他
  3. 正文

Python实用模块推荐3:Pillow、psutil

2017年11月10日 1364点热度 0人点赞 0条评论

PIL即Python Image Library,是python图像处理的标准库,不过它仅仅支持python2,后来有人在原来版本的基础上增加了对python3的支持,就形成了Pillow这个库并且开源了,地址是https://github.com/python-pillow/Pillow
安装Pillow

pip install pillow

from PIL import Image, ImageFilter
# 测试图片大小为400x400
img = Image.open('test.jpg')
# 图像的缩放
w, h = img.size
img.thumbnail((w/2, h/2))
img.save('thumbnail.jpg')
# 图像的模糊,使用的是ImageFilter,它可以做很多事情,如高斯模糊ImageFilter.GaussianBlur、普通模糊ImageFilter.BLUR、边缘增强ImageFilter.EDGE_ENHANCE等等
img_blur = img.filter(ImageFilter.BLUR)
img_blur.save('blur.jpg')
# 图像的裁剪
img_crop = img.crop((0, 0, 200, 200))
img_crop.save('crop.jpg')
# 图像的粘贴,原图像已经变化
img.paste(img_crop, (200, 200))
img.save('paste.jpg')
# 图像的旋转,原图像保持不变
img.rotate(90).save('rotate_90.jpg')
img.rotate(180).save('rotate_180.jpg')
img.rotate(270).save('rotate_270.jpg')
img.rotate(50).save('rotate_50.jpg')

psutils
psutil(process and system utilities)是一个跨平台的获取系统信息(CPU、内存、磁盘、网络等)的库。在linux系统中可以通过一些命令工具来查看系统信息,如top、dstat、vmstat等,如果使用subprocess调用也能实现目标,但是自己解析起来比较麻烦。
安装psutil

1pip install psutil

CPU相关实例

In [1]: import psutil
In [2]: psutil.cpu_times()
Out[2]: scputimes(user=12359.56, nice=30.75, system=2791.42, idle=105554.11, iowait=945.91, irq=0.0, softirq=94.67, steal=0.0, guest=0.0, guest_nice=0.0)
In [7]: psutil.cpu_count()
Out[7]: 4
In [8]: psutil.cpu_count(logical=False)
Out[8]: 2
In [9]: psutil.cpu_stats()
Out[9]: scpustats(ctx_switches=161457633, interrupts=43726924, soft_interrupts=34136310, syscalls=0)
In [10]: psutil.cpu_freq()
Out[10]: scpufreq(current=1829.73775, min=500.0, max=2700.0)

内存相关实例

In [2]: psutil.virtual_memory()
9Out[2]: svmem(total=12505137152, available=5109202944, percent=59.1, used=6563024896, free=887455744, active=7999864832, inactive=2919788544, buffers=939851776, cached=4114804736, shared=508735488, slab=418844672)
In [3]: psutil.swap_memory()
Out[3]: sswap(total=4154454016, used=0, free=4154454016, percent=0.0, sin=0, sout=0)

磁盘相关实例
psutil.disk_partitions()
网络相关实例
psutil.net_io_counters(pernic=True)
Popen封装
p = psutil.Popen(["python", "-c", "print('hello')"], stdout=PIPE)

本作品采用 知识共享署名-禁止演绎 4.0 国际许可协议 进行许可
标签: Pillow psutil
最后更新:2017年11月10日

30115776@qq.com

这个人很懒,什么都没留下

点赞
< 上一篇
下一篇 >

文章评论

您需要 登录 之后才可以评论
最新 热点 随机
最新 热点 随机
阿里巴巴罚款180亿!如何解读? 查理·芒格抄底阿里?是时候仔细审视阿里的价值了 五块钱的激活码和正版Win10,究竟有什么区别? IOS系统不越狱如何下载安装旧版本APP 混动在节能汽车中扮演的角色及技术演进方向 试试这几个电脑清灰的办法,保证不会翻车。
bci是什么组织?试试这几个电脑清灰的办法,保证不会翻车。IOS系统不越狱如何下载安装旧版本APP混动在节能汽车中扮演的角色及技术演进方向五块钱的激活码和正版Win10,究竟有什么区别?查理·芒格抄底阿里?是时候仔细审视阿里的价值了
美区APPLE ID注册及付款方式的解决 自己拍了个视频,但是噪音太大,如何降噪音? 新媒体:网络营销新渠道——以“微信”为例 大学的故事 搜索词、关键词,http、https,免费福利还能享用多久? Rand Fishkin离开他亲手创建的Moz
友情链接
  • 气凝胶厂家
  • 长沙网站建设

COPYRIGHT © 2021 霜天. ALL RIGHTS RESERVED.