-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHEIC.sh
57 lines (46 loc) · 1.56 KB
/
HEIC.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
#!/bin/bash
echo "Pro HEIC converter V1.2"
echo "Enter the quality of output HEIC files in percents (press Enter for default: 75%)"
read quality
if [ -z "$quality" ]; then
quality=75
fi
echo "Select the preset among {ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo} (press Enter for default: medium)"
read preset
if [ -z "$preset" ]; then
preset=medium
fi
echo "Enter the longer side preview length in px (press Enter to skip the preview creation):"
read preview
types=(PNG png JPG jpg JPEG jpeg)
count=0
echo "Enter the number of cores in your device (Enter for default: 4) (it will effect the number of threads used to encode images)"
read ncores
if [ -z "$ncores" ]; then
ncores=4
fi
for type in "${types[@]}"; do
files="*.$type"
if [ -z "$preview" ]; then
echo $files | xargs -P $ncores -n 1 bash -c 'heif-enc -q '$quality' -p preset='$preset' $0; echo "Image $count, done"; ((count++))'
else
echo $files | xargs -P $ncores -n 1 bash -c 'heif-enc -q '$quality' -t '$preview' -p preset='$preset' $0; echo "Image $count, done"; ((count++))'
fi
done
types=(PNG png JPG jpg JPEG jpeg)
for type in "${types[@]}"; do
files=$(ls *.$type 2>/dev/null)
for file in $files; do
base=${file%.*}
heic_file="$base.HEIC"
if [ -f "$heic_file" ]; then
exiftool -tagsfromfile "$file" -r "$heic_file"
exiftool "-filemodifydate<datetimeoriginal" "$heic_file"
fi
done
done
read -p "Do you want to keep backup files? (y/n): " answer
if [ "$answer" == "n" ]; then
rm -f *_original
fi
echo "Work has been finished"