0

Add --optimize-img={1,2} -- performs postprocessing on images

This adds basic post-processing to images. At the moment, it only
performs actions for the png output type, but changes to work for
jpeg will be exceptionall minimal.
This commit is contained in:
Kyle Brantley
2010-10-09 22:57:20 -06:00
parent 05770468fb
commit bcb423ace4
3 changed files with 45 additions and 8 deletions

21
optimizeimages.py Normal file
View File

@@ -0,0 +1,21 @@
import os
import subprocess
import shlex
def optimize_image(imgpath, imgformat, optimizeimg):
if imgformat == 'png':
if optimizeimg == "1" or optimizeimg == "2":
# we can't do an atomic replace here because windows is terrible
# so instead, we make temp files, delete the old ones, and rename
# the temp files. go windows!
subprocess.Popen(shlex.split("pngcrush " + imgpath + " " + imgpath + ".tmp"),
stderr=subprocess.STDOUT, stdout=subprocess.PIPE).communicate()[0]
os.remove(imgpath)
os.rename(imgpath+".tmp", imgpath)
if optimizeimg == "2":
subprocess.Popen(shlex.split("optipng " + imgpath), stderr=subprocess.STDOUT,
stdout=subprocess.PIPE).communicate()[0]
subprocess.Popen(shlex.split("advdef -z4 " + imgpath), stderr=subprocess.STDOUT,
stdout=subprocess.PIPE).communicate()[0]