This repository has been archived by the owner on Jan 19, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjpegtran.py
47 lines (42 loc) · 1.61 KB
/
jpegtran.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
# -*- coding: utf-8 -*-
##############################################################################################
# This file is deprecated because Python 2.x is deprecated #
# A Python 3.x version of this file can be found at: #
# #
# https://github.com/Guymer/PyGuymer3/blob/master/jpegtran.py #
##############################################################################################
def jpegtran(fname):
# Import modules ...
import os
import subprocess
# Check that "jpegtran" is installed ...
try:
subprocess.check_call(
[
u"type",
u"jpegtran"
],
stdout = open(os.devnull, "wt"),
stderr = open(os.devnull, "wt")
)
except subprocess.CalledProcessError:
raise Exception(u"\"jpegtran\" is not installed")
# Check that the JP[E]G exists ...
if not os.path.exists(fname):
raise Exception(u"\"{0:s}\" does not exist".format(fname))
# Optimise JP[E]G ...
try:
subprocess.check_call(
[
u"jpegtran",
u"-copy", u"all",
u"-optimise",
u"-outfile", fname,
u"-perfect",
fname
],
stdout = open(os.devnull, "wt"),
stderr = open(os.devnull, "wt")
)
except subprocess.CalledProcessError:
raise Exception(u"\"jpegtran\" failed")