-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathoptimizeimages.sh
More file actions
44 lines (42 loc) · 1.45 KB
/
Copy pathoptimizeimages.sh
File metadata and controls
44 lines (42 loc) · 1.45 KB
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
# Options : --overwrite, --no-resize, --help
if [ "$1" == "--help" ] ; then
echo
echo "Usage: ./optimizeimages [options ...]"
echo
echo "Options:"
echo -e " --overwrite\tOverwrite original images"
echo -e " --no-resize\tDon't resize images"
echo -e " --help\tShows this help screen"
exit
elif [ "$1" == "--overwrite" ] || [ "$2" == "--overwrite" ] ; then
dir=""
jpegdest=""
else
dir="optimized/"
jpegdest="--dest=optimized"
mkdir optimized 2> /dev/null;
fi
maxsize="1000x600"
if [ "$1" == "--no-resize" ] || [ "$2" == "--no-resize" ] ; then
for f in *;
do
if [ "${f: -4}" == ".jpg" ] || [ "${f: -5}" == ".jpeg" ] || [ "${f: -4}" == ".JPG" ] || [ "${f: -5}" == ".JPEG" ] ; then
jpegoptim --strip-all $jpegdest "$f"
convert "$f" -density 72 -units PixelsPerInch PJPEG:"$dir$f"
elif [ "${f: -4}" == ".png" ] || [ "${f: -4}" == ".PNG" ] ; then
pngout -y "$f" "$dir$f"
fi
done
else
for f in *;
do
if [ "${f: -4}" == ".jpg" ] || [ "${f: -5}" == ".jpeg" ] || [ "${f: -4}" == ".JPG" ] || [ "${f: -5}" == ".JPEG" ] ; then
convert "$f" -resize $maxsize\> -density 72 -units PixelsPerInch PJPEG:"$dir$f"
jpegoptim --strip-all "$dir$f"
convert "$f" PJPEG:"$dir$f" # Necessary because jpegoptim has a bug where if you optimize a PJPEG, it is converted to a normal JPEG
elif [ "${f: -4}" == ".png" ] || [ "${f: -4}" == ".PNG" ] ; then
convert "$f" -resize $maxsize\> -density 72 -units PixelsPerInch "$dir$f"
pngout -y "$dir$f"
fi
done
fi