python重设图片大小
时间: 2023-08-25 07:13:24 浏览: 38
你可以使用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)
```
在上述示例中,你需要将`input_image_path`替换为实际的输入图片路径,`output_image_path`替换为输出图片的保存路径,`size`替换为你想要调整的新尺寸。运行代码后,它将加载输入图片,调整大小并保存为输出图片。