python 旋转图片 拼图
时间: 2023-10-04 17:07:45 浏览: 65
你可以使用Python中的Pillow库来进行图片旋转和拼图。以下是一个示例代码,其中包括了旋转图片和拼图的功能:
```
from PIL import Image
# 旋转图片
def rotate_image(image_path, degrees):
with Image.open(image_path) as image:
rotated_image = image.rotate(degrees)
rotated_image.save('rotated_image.jpg')
# 拼图
def merge_images(image_paths, output_path):
images = [Image.open(image_path) for image_path in image_paths]
widths, heights = zip(*(i.size for i in images))
total_width = sum(widths)
max_height = max(heights)
new_image = Image.new('RGB', (total_width, max_height))
x_offset = 0
for image in images:
new_image.paste(image, (x_offset,0))
x_offset += image.size[0]
new_image.save(output_path)
# 示例
rotate_image('image.jpg', 45)
merge_images(['image1.jpg', 'image2.jpg', 'image3.jpg'], 'merged_image.jpg')
```
你可以根据自己的需求修改代码中的参数和文件路径,并使用以上代码来实现图片旋转和拼图的功能。
阅读全文