from PIL import Image import os def resize_geotiff(input_path, output_path, factor=0.5): try: img = Image.open(input_path) width, height = img.size new_width = int(width * factor) new_height = int(height * factor) resized_img = img.resize((new_width, new_height), Image.ANTIALIAS) resized_img.save(output_path) print(f"Resized {input_path} and saved to {output_path}") except Exception as e: print(f"Error processing {input_path}: {e}") def batch_resize_geotiffs(input_folder, output_folder, factor=0.5): if not os.path.exists(output_folder): os.makedirs(output_folder) for filename in os.listdir(input_folder): if filename.endswith(".tif") or filename.endswith(".tiff"): input_path = os.path.join(input_folder, filename) output_path = os.path.join(output_folder, filename) resize_geotiff(input_path, output_path, factor) if __name__ == "__main__": input_folder = "kosher" output_folder = "kosher/new" resize_factor = 0.5 batch_resize_geotiffs(input_folder, output_folder, resize_factor)