Skip to content

Instantly share code, notes, and snippets.

@skarfie123
Created September 2, 2023 21:15
Show Gist options
  • Save skarfie123/9cc5f7e142b66dd954c21a7f2e8b34d3 to your computer and use it in GitHub Desktop.
Save skarfie123/9cc5f7e142b66dd954c21a7f2e8b34d3 to your computer and use it in GitHub Desktop.
convert BMP images to PNG
import os
from PIL import Image
def main():
input_folder = "output"
# List all files in the input folder
bmp_files = [f for f in os.listdir(input_folder) if f.lower().endswith(".bmp")]
for bmp_file in bmp_files:
# Open the BMP image
bmp_image = Image.open(os.path.join(input_folder, bmp_file))
# Create the corresponding PNG filename
png_file = os.path.splitext(bmp_file)[0] + ".png"
png_path = os.path.join(input_folder, png_file)
# Save the BMP image as PNG
bmp_image.save(png_path, "PNG")
print("All BMP images converted to PNG successfully.")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment