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 pathoptipng.py
43 lines (38 loc) · 1.48 KB
/
optipng.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
# -*- 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/optipng.py #
##############################################################################################
def optipng(fname):
# Import modules ...
import os
import subprocess
# Check that "optipng" is installed ...
try:
subprocess.check_call(
[
u"type",
u"optipng"
],
stdout = open(os.devnull, "wt"),
stderr = open(os.devnull, "wt")
)
except subprocess.CalledProcessError:
raise Exception(u"\"optipng\" is not installed")
# Check that the image exists ...
if not os.path.exists(fname):
raise Exception(u"\"{:s}\" does not exist".format(fname))
# Optimise PNG ...
try:
subprocess.check_call(
[
u"optipng",
fname
],
stdout = open(os.devnull, "wt"),
stderr = open(os.devnull, "wt")
)
except subprocess.CalledProcessError:
raise Exception(u"\"optipng\" failed")