Python中使用Pillow库,如何把图片尺寸调整为宽480px,高640px?
时间: 2024-03-24 17:39:18 浏览: 22
使用Pillow库可以很方便地将图片尺寸调整为所需大小。以下是一些基本的步骤:
1. 安装Pillow库。可以通过pip命令在终端或命令提示符中安装。
```
pip install Pillow
```
2. 导入Pillow库中的Image模块。
```python
from PIL import Image
```
3. 打开需要调整大小的图片。
```python
img = Image.open("path/to/image.jpg")
```
4. 调用resize()方法,并传递所需的宽度和高度作为参数。
```python
img_resized = img.resize((480, 640))
```
5. 将处理后的图像保存到文件中。
```python
img_resized.save("path/to/resized-image.jpg")
```
完整的代码示例:
```python
from PIL import Image
img = Image.open("path/to/image.jpg")
img_resized = img.resize((480, 640))
img_resized.save("path/to/resized-image.jpg")
```
这样就可以将图片的尺寸调整为宽480px,高640px,并保存到指定的文件中。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)