Created
August 15, 2023 09:17
-
-
Save MichaelHolley/e936890e66b3c0f2e3896f42c1da21c8 to your computer and use it in GitHub Desktop.
a python script to convert .nef files from a input directory to .jpg
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
import os | |
import rawpy | |
from PIL import Image | |
def convert_nef_to_jpg(input_dir, output_dir): | |
if not os.path.exists(output_dir): | |
os.makedirs(output_dir) | |
for filename in os.listdir(input_dir): | |
if filename.lower().endswith('.nef'): | |
input_path = os.path.join(input_dir, filename) | |
output_path = os.path.join(output_dir, os.path.splitext(filename)[0] + '.jpg') | |
raw = rawpy.imread(input_path) | |
rgb = raw.postprocess() | |
img = Image.fromarray(rgb) | |
img.save(output_path, 'JPEG') | |
print(f"Converted {filename} to {os.path.basename(output_path)}") | |
if __name__ == "__main__": | |
input_directory = "input/" | |
output_directory = "output/" | |
convert_nef_to_jpg(input_directory, output_directory) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment