import os import subprocess TARGET_DIR = "/Users/davidkotnik/Desktop/referencne slike 2" def convert_images(): if not os.path.exists(TARGET_DIR): print(f"Error: Directory {TARGET_DIR} does not exist.") return files = [f for f in os.listdir(TARGET_DIR) if f.lower().endswith(('.jpg', '.jpeg'))] if not files: print("No JPG images found to convert.") return print(f"Found {len(files)} JPG images. Starting conversion...") for filename in files: filepath = os.path.join(TARGET_DIR, filename) name_without_ext = os.path.splitext(filename)[0] new_filename = name_without_ext + ".png" new_filepath = os.path.join(TARGET_DIR, new_filename) # Skip if png already exists to save time? # User said "first convert", implyng they might not exist. # But let's overwrite to be sure we have fresh versions if needed. try: # Using macOS built-in sips tool subprocess.run( ["sips", "-s", "format", "png", filepath, "--out", new_filepath], check=True, stdout=subprocess.DEVNULL # Silence standard output for cleaner logs ) print(f"✅ Converted: {filename} -> {new_filename}") except subprocess.CalledProcessError as e: print(f"❌ Failed to convert {filename}: {e}") if __name__ == "__main__": convert_images()