forked from maxim-saplin/BulkConverterToHeic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheic_magick.sh
82 lines (66 loc) · 1.6 KB
/
heic_magick.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
#!/bin/zsh
#setopt interactivecomments
setopt +o nomatch
start=`date +%s`;
cd $1;
remove=0
subfolders=0
path_wildcard="*."
if [[ "$2" = "remove" || "$3" = "remove" ]];
then
remove=1
fi
if [[ "$2" = "subfolders" || "$3" = "subfolders" ]];
then
subfolders=1
path_wildcard="**/*."
fi
exts=("jpg" "jpeg" "bmp" "png")
echo CONVERTING FILES WITH EXTENSIONS: $exts;
if [[ $subfolders -eq 1 ]];
then
echo SUBFOLDERS INCLUDED
fi
if [[ $remove -eq 1 ]];
then
echo ORIGINAL FILES WILL BE REMOVED AFTER CONVERSION
fi
glob_total=0;
glob_success=0;
for ext in $exts; do
echo " ";
echo "PROCESSING $ext ->";
echo " ";
total=0;
success=0;
#for src in find . -name "*.$ext"; do
for src in $~path_wildcard$ext; do
if [[ "$src" = "$path_wildcard$ext" ]];
then
continue # If there're no files the glob expressions can be returned instead, e.g. **/*.jpg
fi
echo "\t$src";
dst="$(echo "$src" | sed -e 's/\.[^.]*$//').heic"; # remove original extension and replace it with heic
#dst="${src%.jpg}.HEIC";
#echo "$src -> $dst";
magick $src $dst #&& ((success++));
if [[ $? -eq 0 ]]; then
((success++));
if [ $remove -eq 1 ]; then
rm $src
#echo Removed $src
fi
else
#echo "magick exited with error code"
fi
((total++));
done;
((glob_total=total+glob_total));
((glob_success=success+glob_success));
echo " ";
echo "TOTAL '$ext' FILES: $total, SUCCESSFUL: $success";
echo "TOTAL FILES SO FAR: $glob_total, SUCCESSFUL: $glob_success";
echo " ";
done;
end=`date +%s`;
echo TIME: `expr $end - $start` seconds.;