-
Notifications
You must be signed in to change notification settings - Fork 0
/
avatars.sh
executable file
·68 lines (60 loc) · 1.38 KB
/
avatars.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
# uses https://github.com/sindresorhus/file-type-cli
filemap=""
addComma="no"
function getAvatar() {
filename=$1
src=$2
wget --quiet -O img/${filename} $src
}
function optimizeImageByFileName() {
handle=$1
extension=$1
file="img/${filename}"
type=$(file-type $file)
if [[ $type == *"image/jpeg"* ]]
then
jpegtran "$file" > "$file."
mv "$file." "$file"
fi
if [[ $type == *"image/png"* ]]
then
pngcrush -brute "$file"{,.}
rm "img/${filename}"
mv "img/${filename}." "img/${filename}"
fi
}
function optimizeImage() {
handle=$1
file="img/${handle}.jpg"
type=$(file-type $file)
if [[ $type == *"image/jpeg"* ]]
then
jpegtran "$file" > "$file."
mv "$file." "$file"
fi
if [[ $type == *"image/png"* ]]
then
pngcrush -brute "$file"{,.}
rm img/${handle}.jpg
mv img/${handle}.jpg. img/${handle}.png
if [[ "$addComma" == "no" ]]
then
addComma="yes"
else
filemap="$filemap,"
fi
filemap="$filemap\n\t\"$handle\": \"$handle.png\""
fi
}
# Testimonials
for handle in $(cat _data/speakers.json | jq -r '.[] | .twitter'); do
if [[ "$handle" == "" || "$handle" == "null" ]]
then
echo "$handle is not valid";
else
echo ${handle}
getAvatar "$handle.jpg" "https://twitter.com/${handle}/profile_image?size=bigger"
optimizeImage $handle
fi
done
echo "{$filemap\n}" > _data/avatarFileMap.json