Mac工作流之图片压缩
需要安装命令行插件
pngquant
jpegoptim
gifsicle
import sys
import subprocess as sp
import os
import json
import shutil
my_env = os.environ.copy()
my_env["PATH"] = "/usr/local/bin:" + my_env["PATH"]
# Note: The first argument is the script's path
for arg in sys.argv[1:]:
fileType = (os.path.splitext(arg)[-1]).lower()
if fileType == ".png":
my_command = ["pngquant", arg, "--quality", "70-95", "--ext=.png", "--force"]
sp.check_output(my_command, env=my_env)
elif fileType == ".jpg" or fileType == ".jpeg":
my_command = ["jpegoptim", "-m70", "--max90", arg]
sp.check_output(my_command, env=my_env)
elif fileType == ".gif":
my_command = ["gifsicle", "-i", arg, "--optimize=3", "-o", arg]
sp.check_output(my_command, env=my_env)
未经作者授权,禁止转载
本文来自博客园,作者:CoderWGB,转载请注明原文链接:https://www.cnblogs.com/wgb1234/p/17372642.html
THE END