-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbatch_rotate_images.sh
48 lines (39 loc) · 1.21 KB
/
batch_rotate_images.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
#!/bin/bash
if ! command -v ffmpeg &> /dev/null; then
echo "Error: FFmpeg is not installed. Please install FFmpeg and try again."
exit 1
fi
if [ $# -lt 4 ]; then
echo "Error: Please provide input folder, output folder, image format as command-line arguments."
echo "Usage: $0 <input_folder> <output_folder> --format <image_format>"
exit 1
fi
input_folder="$1"
output_folder="$2"
image_format="$4"
if [ ! -d "$input_folder" ]; then
echo "Error: Input image folder does not exist."
exit 1
fi
mkdir -p "$output_folder"
case "$image_format" in
jpg|jpeg|png)
;;
*)
echo "Error: Unsupported image format: $image_format. Supported formats: jpg, jpeg, png"
exit 1
;;
esac
shopt -s nullglob
for file in "$input_folder"/*."$image_format"; do
if ! file --mime-type "$file" | grep -qE "image/(jpeg|png)"; then
echo "Skipping non-image file: $file"
continue
fi
filename=$(basename -- "$file")
output_file="$output_folder/${filename%.*}_rotated.$image_format"
if ! ffmpeg -i "$file" -vf "transpose=2" "$output_file"; then
echo "Error: Failed to process file $file. Check FFmpeg installation and try again."
fi
done
shopt -u nullglob