Created
January 1, 2024 14:57
-
-
Save abeldantas/7c456dfbe2982e435c51261888ae68d3 to your computer and use it in GitHub Desktop.
TIF to PNG Converter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image | |
import os | |
import sys | |
def convert_tif_to_png(src_path, dest_path): | |
if not os.path.exists(dest_path): | |
os.makedirs(dest_path) | |
for root, dirs, files in os.walk(src_path): | |
for file in files: | |
if file.lower().endswith('.tif'): | |
img_path = os.path.join(root, file) | |
img = Image.open(img_path) | |
file_without_ext = os.path.splitext(file)[0] | |
img.save(os.path.join(dest_path, file_without_ext + '.png'), "PNG") | |
def main(): | |
if len(sys.argv) != 3: | |
print("Usage: python tif_to_png_converter.py [source_path] [destination_path]") | |
return | |
src_path = sys.argv[1] | |
dest_path = sys.argv[2] | |
convert_tif_to_png(src_path, dest_path) | |
print(f"Conversion completed. Files saved to {dest_path}") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment