-
Notifications
You must be signed in to change notification settings - Fork 1
/
jpg2avif
38 lines (34 loc) · 1008 Bytes
/
jpg2avif
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
#!/bin/bash
# Description: This script converts all .jpg format in current directory to .avif format.
# Dependency: imagemagick
# Check if ImageMagick is installed
if ! command -v convert &> /dev/null; then
echo "ImageMagick is required but not installed. Please install it first."
exit 1
fi
count=0
skipped=0
total=$(ls -1 *.jpg 2>/dev/null | wc -l)
if [[ $total -eq 0 ]]; then
echo "No .jpg files found in the current directory."
exit 0
fi
for file in *.jpg; do
if [[ -e "${file%.jpg}.avif" ]]; then
echo "Skipping $file already exists."
skipped=$((skipped+1))
continue
fi
# Converting into JPG
convert -auto-orient "$file" "${file%.jpg}.avif"
if [[ $? -ne 0 ]]; then
echo "Error converting file: $file"
else
count=$((count+1))
echo "Converted file $count of $total: $file"
fi
done
echo "---------------------------"
echo "Converted files: $count"
echo "Skipped files : $skipped"
echo "---------------------------"