[英]how to replace jpg images with png images
I have Jpg images which are in one folder. 我有一个文件夹中的Jpg图像。 I want to replace that images with png format in the same folder and same name.how to do this?
我想用相同文件夹和名称中的png格式替换这些图像。如何执行此操作? here what i tried:
这是我尝试的:
image_path =''
input_image = Image.open(image_path).convert('RGB')
input_image.save(image_path + ".png", "PNG")
form a list of files with os.listdir() and iterate them with a for loop. 使用os.listdir()形成文件列表,并使用for循环对其进行迭代。
import os
image_path ='some_path/'
for img in os.listdir(image_path):
input_image = Image.open(image_path+img).convert('RGB')
input_image.save(image_path+img + ".png", "PNG")
Hope this helps! 希望这可以帮助! Cheers!
干杯!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.