📜  Python PIL | paste() 和 rotate() 方法

📅  最后修改于: 2022-05-13 01:54:52.187000             🧑  作者: Mango

Python PIL | paste() 和 rotate() 方法

PIL 是Python Imaging Library,它为Python解释器提供了图像编辑功能。

PIL.Image.Image.paste()方法用于将图像粘贴到另一个图像上。这就是 new() 方法派上用场的地方。

Python3
# Importing Image module from PIL package
from PIL import Image
 
# creating a image object (main image)
im1 = Image.open(r"C:\Users\Admin\Pictures\network.PNG")
 
# creating a image object (image which is to be paste on main image)
im2 = Image.open(r"C:\Users\Admin\Pictures\geeks.PNG")
 
# pasting im2 on im1
Image.Image.paste(im1, im2, (50, 125))
 
# to show specified image
im1.show()


Python3
# Importing Image module from PIL package
from PIL import Image
import PIL
 
# creating a image object (main image)
im1 = Image.open(r"C:\Users\Admin\Pictures\network.PNG")
 
# rotating a image 90 deg counter clockwise
im1 = im1.rotate(90, PIL.Image.NEAREST, expand = 1)
 
# to show specified image
im1.show()


输出:

PIL.Image.Image.rotate() 方法 –

此方法用于将给定图像围绕其中心逆时针旋转给定度数。

Python3

# Importing Image module from PIL package
from PIL import Image
import PIL
 
# creating a image object (main image)
im1 = Image.open(r"C:\Users\Admin\Pictures\network.PNG")
 
# rotating a image 90 deg counter clockwise
im1 = im1.rotate(90, PIL.Image.NEAREST, expand = 1)
 
# to show specified image
im1.show()

输出:

使用的图像 –