-
Notifications
You must be signed in to change notification settings - Fork 0
/
Files_ConvertWebpToJpeg.sh
70 lines (50 loc) · 1.54 KB
/
Files_ConvertWebpToJpeg.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
desiredsize=1024
desiredquality=70%
# get folder size beforeTotal
beforeTotal=$(du -hc $PWD | tail -n 1)
for dir in *; do
cd $dir
echo "Working in folder $PWD"
# get folder size before
before=$(du -hc $PWD | tail -n 1)
# make all spaces to underscore
echo " > All spaces to underscore..."
find $PWD -depth -name '* *' -execdir bash -c 'mv -- "$1" "${1// /_}"' bash {} \;
# make all file extensions lower case
echo " > All file extensions to lower case..."
rename -f 's/\.([^.]+)$/.\L$1/' *
# Renaming jpeg to jpg
echo " > Renaming JPEG to JPG..."
for file in *.jpeg; do
mv "$file" "$(basename "$file" .jpeg).jpg" &> /dev/null
done
# convert webp to png
echo " > Converting WebP to PNG..."
var=$(find . -depth -maxdepth 1 -name "*.webp" -print0 | parallel -0 dwebp {} -quiet -o {.}.png)
rm *.webp &> /dev/null
# convert all png to jpg
echo " > Converting PNG to JPG..."
find . -depth -maxdepth 1 -name "*.png" -exec mogrify -format jpg {} \;
rm *.png &> /dev/null
# Reduce quality of jpg
echo " > Converting to desired quality..."
mogrify -quality $desiredquality *.jpg &> /dev/null
# resize all jpg
echo " > Resizing all images..."
for file in *.jpg; do convert $file -resize $desiredsize\> $file; done
# get folder size after
after=$(du -hc $PWD | tail -n 1)
echo "Finished."
# print sizes
echo "Size before : $before"
echo "Size after : $after"
echo " "
cd ..
done
# get folder size afterTotal
afterTotal=$(du -hc $PWD | tail -n 1)
# print sizes
echo "Size before : $beforeTotal"
echo "Size after : $afterTotal"
#cd back to where we started
cd $OLDPWD