感谢优秀的你打开了小白的文章
“希望在看文章的你今天又进步了一点点,离美好生活更近一步!”
在 Pillow 库的 Image 模块中,函数 rotate()的功能返回此图像的副本,围绕其中心逆时 针旋转给定的度数。
mage.rotate(angle,resample = 0,expand = 0,center = None,translate = None,fillcolor = None )
在 Pillow 库的 Image 模块中,函数 transpose()函数功能是实现图像格式的转换。
具体语法格式如下:
Image.transpose(method)
转换图像后,返回转换后的图像,“method”的取值有以下几个。
1. PIL.Image.FLIP_LEFT_RIGHT:左右镜像
2. PIL.Image.FLIP_TOP_BOTTOM :上下镜像
3. PIL.Image.ROTATE_90:旋转 90
4. PIL.Image.ROTATE_180:旋转 180
5. PIL.Image.ROTATE_270:旋转 270
6. PIL.Image.TRANSPOSE :颠倒顺序
代码实例:
from PIL import Imageimg=Image.open('p2.jpg')img2=img.copy()#图像的旋转# img.rotate(180).show()#格式转换img.transpose(Image.FLIP_TOP_BOTTOM).show() # 上下滤镜# img.transpose(Image.FLIP_LEFT_RIGHT).show() # 左右滤镜# img.transpose(Image.ROTATE_90).show() # 90滤镜#img.transpose(Image.ROTATE_180).show() # 180滤镜#img.transpose(Image.TRANSPOSE).show() # 颠倒滤镜
运行结果(上下滤镜):
在 Pillow 库的 Image 模块中,函数 convert()的功能是返回模式转换后的图像实例。
具体转换的语法格式如下:
Image.convert(mode=None,matrix=None,dither=None,palette=0,colors=256)
其中 mode:转换文件的模式,默契支持的模式有“L”、“RGB”“CMYK”;matrix: 转使用的矩阵;dither:取值为 None 切转为黑白图时非 0(1-255)像素均为白,也可以设置此参数为 FLOYDSTEINBERG.
实例代码:
from PIL import Imageimg=Image.open('p2.jpg')img2=img.copy()#convert()img_convert=img2.convert('L')img_convert.show()
结果如下:
代码可在公众号获取