forked from alrra/browser-logos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-images.sh
executable file
·156 lines (123 loc) · 3.63 KB
/
generate-images.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/bin/bash
# This script automatically generates the `main-desktop.png` and the
# `main-mobile.png` images as well as all the different sized versions
# of the logos, but in order for it to work, you will need to have
# ImageMagick's convert command-line tool installed.
#
# http://www.imagemagick.org/script/convert.php
#
# Usage: generate-images.sh [dir] [dir] ...
# e.g: generate-images.sh chrome archive/arora
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
declare -r CONVERT_BASE_OPTIONS="\
-colorspace RGB \
+sigmoidal-contrast 11.6933 \
-define filter:filter=Sinc \
-define filter:window=Jinc \
-define filter:lobes=3 \
-sigmoidal-contrast 11.6933 \
-colorspace sRGB \
-background transparent \
-gravity center \
"
declare -r -a IMAGE_SIZES=(
'16x16'
'24x24'
'32x32'
'48x48'
'64x64'
'128x128'
'256x256'
'512x512'
)
declare -r -a MAIN_DESKTOP_BROWSERS=(
"chrome"
"firefox"
"internet-explorer"
"opera"
"safari"
)
declare -r -a MAIN_MOBILE_BROWSERS=(
"android"
"chrome-android"
"firefox"
"internet-explorer-tile"
"opera-mini"
"safari-ios"
"uc"
)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
generate_group_image() {
declare -a imageDirs=("${!1}"); shift;
local imageName="$1.png"; shift;
local generate="false"
# Do not regenerate the group image if
# none of the composing images are modified
while [ $# -ne 0 ] && [ "$generate" != "true" ]; do
if [[ "${imageDirs[*]}" =~ "$1" ]]; then
generate="true"
break;
fi
shift
done
if [ "$generate" == "true" ]; then
for i in ${imageDirs[@]}; do
tmp+=("$i/$i.png")
done
convert "${tmp[@]}" \
$CONVERT_BASE_OPTIONS \
-resize 512x512 \
-extent 562x562 \
+append \
"$imageName" \
&& print_success_msg "[create] $imageName" \
|| print_error_msg "[create] $imageName"
fi
}
generate_images() {
local basename=''
local imageDirs=($@)
local path=''
for i in ${imageDirs[@]}; do
basename=$(basename $i)
path="$(dirname $i)/$basename"
if [ ! -f "$path/$basename.png" ]; then
print_error_msg "'$path/$basename.png' does not exist!"
continue
fi
# Remove outdated images
rm ${path}/${basename}_* &> /dev/null
# Generate the different sized versions of the image
for s in ${IMAGE_SIZES[@]}; do
convert "$path/$basename.png" \
$CONVERT_BASE_OPTIONS \
-resize "$s" \
"$path/${basename}_$s.png" \
&& print_success_msg "[create] $path/${basename}_$s.png" \
|| print_error_msg "[create] $path/${basename}_$s.png"
done
done
}
print_error_msg() {
printf "\e[0;31m $1\e[0m\n"
}
print_success_msg() {
printf "\e[0;32m $1\e[0m\n"
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
main() {
# Check if ImageMagick's convert command-line tool is installed
if [ -x "$(command -v "convert")" ]; then
# Ensure that the following actions
# are made relative to the project root
cd "$(dirname ${BASH_SOURCE[0]})"
printf "\n"
generate_images $@
generate_group_image MAIN_DESKTOP_BROWSERS[@] "main-desktop" $@
generate_group_image MAIN_MOBILE_BROWSERS[@] "main-mobile" $@
printf "\n"
else
print_error_msg "Please install ImageMagick's \`convert\` command-line tool!"
fi
}
main $@