简体   繁体   English

如何用png图像替换jpg图像

[英]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.

相关问题 将 .jpg 图像转换为 .png - Converting .jpg images to .png 在 python 中将图像 PNG 转换为 JPG - Converting Images PNG to JPG in python 将 PNG 图像从文件夹转换为 JPG - Python - Convert PNG images from folder to JPG - Python 如何使用 url(不包含 .jpg、.png 等)使用 Python 下载 Flickr 图像 - How to download Flickr images using photos url (does not contain .jpg, .png, etc.) using Python 我在 DICOM 图像中有一个数据,我想将 dicom 图像转换为 png 或 jpg 格式。 但是如何使用 for 循环一次转换文件夹数 - I have a Data in DICOM images i want to convert dicom images in to png or jpg format . but how to convert Number of folders at once with for loop png,jpg图像在pygame中无法正确显示(mac osx pycharm / IDLE) - png, jpg images not displaying properly in pygame (mac osx pycharm / IDLE) 用魔杖转换为PNG的jpg图像变得更大 - jpg images converted to PNG with wand get much larger Python:需要从URL循环下载图像(JPG和PNG) - Python: Need to download images from URL in a loop (JPG and PNG) 是否可以禁用在Selenium和Chrome Webdrive上加载图像(仅jpg和png)? - Is it possible to disable loading images (jpg and png only) on Selenium and Chrome webdrive? 为什么在 .png 格式的图像中检测到彩色像素,但在 .jpg 格式的图像中检测不到? - Why are colour pixels detected in .png format images but not in those in .jpg format?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM