python调整图片大小
时间: 2023-07-14 12:05:39 浏览: 131
要使用Python调整图片的大小,你可以使用PIL库(Python Imaging Library)来实现。下面是一个示例代码:
```python
from PIL import Image
def resize_image(input_image_path, output_image_path, size):
original_image = Image.open(input_image_path)
width, height = original_image.size
print(f"The original image size is {width} wide x {height} tall")
resized_image = original_image.resize(size)
width, height = resized_image.size
print(f"The resized image size is {width} wide x {height} tall")
resized_image.save(output_image_path)
# 示例调用
input_image = "input.jpg"
output_image = "output.jpg"
new_size = (800, 600)
resize_image(input_image, output_image, new_size)
```
在上面的示例中,`resize_image`函数接受输入图片路径、输出图片路径和目标大小作为参数。它首先使用`Image.open`方法打开原始图片,然后使用`resize`方法调整图片的尺寸。最后,使用`save`方法保存调整后的图片。
你可以根据自己的需求修改示例代码中的参数。
阅读全文
相关推荐














