-
Notifications
You must be signed in to change notification settings - Fork 0
/
heic2jpg.py
64 lines (51 loc) · 1.74 KB
/
heic2jpg.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
import os
import argparse
import platform
from sys import exit
from convert import *
parser = argparse.ArgumentParser()
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument("-d", "--directory", dest="dirPath", help="The input directory.")
group.add_argument("-f", "--file", dest="filename", help="The input fingle file.")
parser.add_argument("-o", "--output", help="The output directory.",
dest="outputDir")
parser.add_argument("-r", "--recursive", help="Use recursive mode",
action="store_true")
parser.add_argument("-t", "--type", help="Output image type.",
dest="outputFormat")
args = parser.parse_args()
# 處理參數
outputDir = args.outputDir
isRecursive = args.recursive
outputFormat = args.outputFormat
if(outputFormat == None):
outputFormat = "jpeg"
try:
ci = ConvertImage(outputFormat)
print("輸出格式:", outputFormat)
except FormatNotSupport:
print("Support format:")
ConvertImage.supportFormat()
exit(1)
if(args.dirPath != None):
try:
if(args.recursive):
print("recursive mode on")
ci.convertRecursive(args.dirPath, outputDir)
else:
ci.convertDir(args.dirPath, outputDir)
except ConvertImageDirNotFound:
print("Err:", args.dirPath)
print("找不到路徑或無效路徑")
except CanNotConvertImage:
print("無法轉換檔案")
elif(args.filename != None):
try:
ci.convertFile(args.filename, outputDir)
except CanNotConvertImage:
print("無法轉換檔案")
except ConvertImageFileNotFound:
print("Err:", args.filename)
print("找不到檔案")
print("All done!")
input("輸入任意鍵繼續")