-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNEF2PNGPlus.py
92 lines (63 loc) · 2.84 KB
/
NEF2PNGPlus.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import os
import subprocess
import time
from tkinter import filedialog
NEFnames = []
global irfanviewPath
def getNEFnames(folder_path):
files = [f for f in os.listdir(folder_path) if os.path.isfile(os.path.join(folder_path, f))]
NEFfiles = [f for f in files if f.endswith(".NEF")]
return NEFfiles
def convertNEFtoPNG(fileList, input_folder, output_folder):
if isinstance(fileList, list):
possible_path = "C:\Program Files (x86)\IrfanView\i_view32.exe", "C:\Program Files (x86)\IrfanView\i_view64.exe", "C:\Program Files\IrfanView\i_view32.exe", "C:\Program Files\IrfanView\i_view64.exe"
for path in possible_path:
if os.path.isfile(path) and os.path.exists(path):
irfanviewPath = path
try:
irfanviewPath
except:
irfanviewPath = select_irfan_folder()
do_converting(fileList, input_folder, output_folder, irfanviewPath)
def main():
input_folder = select_input_folder()
if not input_folder:
print("No input folder selected.")
print("Input folder selected: " + input_folder)
output_folder = select_output_folder()
if not output_folder:
print("No output folder selected.")
print("Output folder selected: " + output_folder)
NEFnames = getNEFnames(input_folder)
if not NEFnames:
print("Warning: No NEF files found in the selected input folder.")
print("Trying to convert " + str(len(NEFnames)) + " files")
convertNEFtoPNG(NEFnames, input_folder, output_folder)
print("Successfully Finished Converting")
time.sleep(2)
def select_input_folder():
"""Select the input folder using a file dialog"""
input_folder = filedialog.askdirectory(title="Select Input Folder").replace('/', '\\')
return input_folder
def select_output_folder():
"""Select the output folder using a file dialog"""
output_folder = filedialog.askdirectory(title="Select Output Folder").replace('/', '\\')
return output_folder
def select_irfan_folder():
"""Select the output folder using a file dialog"""
irfanviewPath = filedialog.askopenfile(title="Select Irfan Folder").name
print(irfanviewPath)
return irfanviewPath
def do_converting(fileList, input_folder, output_folder, irfanviewPath):
for f in fileList:
input_path = os.path.join(input_folder, f)
output_path = os.path.join(output_folder, os.path.splitext(f)[0] + " Converted.png")
print("Converting:", input_path)
for x in range(len(fileList)):
try:
subprocess.run([irfanviewPath, input_path, '/convert=',
output_path])
except:
print("Issue found when attempting to convert " + input_path)
if __name__ == '__main__':
main()