-
Notifications
You must be signed in to change notification settings - Fork 0
/
heic轉JPG.py
37 lines (33 loc) · 1.1 KB
/
heic轉JPG.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
# -*- coding: utf-8 -*-
#python 2 or python 3
# 可以用語法做批次轉檔 python exercise.py -q 100(最高) *(代表所有檔案) ./(輸出到原本資料夾)
'''
這些是必要裝得套件
sudo add-apt-repository ppa:strukturag/libheif
sudo apt-get update
sudo apt-get install libheif-examples
'''
import subprocess, os, sys
from os import listdir
from os.path import isfile, join
try:
subprocess.call(['heif-convert'])
subprocess.call(['clear'])
try:
路徑 = os.getcwd()
files = [f for f in listdir(路徑) if isfile(join(路徑, f))]
for file in files:
(name, ext) = os.path.basename(file).split('.')
if ext == 'heic' or ext == 'HEIC':
dest = name + '.jpg'
orig = file
print(dest)
print(orig)
try:
subprocess.call(['heif-convert', orig, dest])
except:
print("語法錯誤或檔案有問題: %s", orig)
except:
print("語法錯誤")
except:
print("套件錯誤")