-
-
Notifications
You must be signed in to change notification settings - Fork 417
/
Copy pathimage_compressor.sh
executable file
·65 lines (53 loc) · 2.03 KB
/
image_compressor.sh
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
# =========================================
# image_compressor.sh
# Copyright 2017 Christopher Simpkins
# MIT License
# =========================================
# Executes image compression on png files with the dependencies:
#################################################################
# imageoptim-cli
#################################################################
# Project Source : https://github.com/JamieMason/ImageOptim-CLI
# Please see above project page for dependencies
# imageoptim-cli Usage: imageOptim [options]
# Options:
# -d, --directory directory of images to process
# -a, --image-alpha pre-process PNGs with ImageAlpha.app *
# -j, --jpeg-mini pre-process JPGs with JPEGmini.app **
# -q, --quit quit all apps when complete
# -c, --no-color disable color output
# -h, --help display this usage information
# -e, --examples display some example commands and uses
# -v, --version display the version number
##################################################################
# ImageOptim
##################################################################
# URL: https://imageoptim.com/
# CL Usage: https://imageoptim.com/command-line.html
# image_compressor.sh Usage
#
# Excecute image compression on all png images in the Codeface repository
# $ ./image_compressor.sh
#
# Excecute image compression on a set of defined images
# $ ./image_compressor.sh [image path 1] <image path 2> ...
if [ $# -eq 0 ]; then
# excecute imageoptim-cli on all png files in the images directory
find ../images/gallery -name '*.png' | imageOptim -a
else
for file in "$@";
do
if [ -f "$file" ]; then
# pngquant on requested files
echo "pngquant on '$file' started"
pngquant --ext=.png --force --speed=1 --quality=75-100 --skip-if-larger "$file"
echo "pngquant on '$file' completed successfully"
else
echo "'$file' does not appear to be a file." >&2
exit 1
fi
done;
# ImageOptim all requested post-pngquant files
open -a ImageOptim "$@"
fi