rgb的png像素由1024*1024批量转宽1241高376并保存为rgb
时间: 2023-10-16 17:22:25 浏览: 31
你可以使用Python中的Pillow库来批量转换PNG图片的大小并保存为RGB模式。以下是一个示例代码:
``` python
from PIL import Image
import os
# 设置输入和输出目录
input_dir = "/path/to/input/dir"
output_dir = "/path/to/output/dir"
# 设置目标大小
target_width = 1241
target_height = 376
# 批量转换PNG图片大小并保存为RGB模式
for file_name in os.listdir(input_dir):
if file_name.endswith(".png"):
# 打开图片
input_path = os.path.join(input_dir, file_name)
image = Image.open(input_path)
# 调整大小
resized_image = image.resize((target_width, target_height))
# 转换为RGB模式
rgb_image = resized_image.convert("RGB")
# 保存图片
output_path = os.path.join(output_dir, file_name)
rgb_image.save(output_path)
```
将代码中的`/path/to/input/dir`和`/path/to/output/dir`替换为你的实际输入和输出目录,并保存为一个Python脚本。然后运行脚本,它将批量转换PNG图片的大小并保存为RGB模式。
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)