-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgif.sh
executable file
·52 lines (40 loc) · 1.38 KB
/
gif.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
#!/bin/bash
files=$1
num_images=$2
base_dir=$(dirname "$files")
if [ -z "$num_images" ]; then
num_images=1
fi
# Check if files.txt exists
if [ ! -f "$files" ]; then
echo "Error: files.txt not found"
exit 1
fi
# Create a directory for the annotated images
output_dir="$base_dir/annotated_images"
mkdir -p "$output_dir"
echo >"$base_dir/annotated.txt"
# Read filenames from files.txt and process each file
total_files=$(wc -l < "$files")
step_size=$(( total_files / num_images ))
echo "STEP SIZE:" $step_size
counter=0
current_file=-1
while IFS= read -r filename && [ $counter -lt $num_images ]; do
if [ "$current_file" -eq -1 ] || [ "$current_file" -eq "$step_size" ]; then
echo $current_file
# Extract filename without extension
file_name=$(basename "$filename" | cut -d. -f1)
# Build the output file path
output_file="$output_dir/${file_name}.png"
echo "$output_file">>"$base_dir/annotated.txt"
# Run the convert command to annotate and add a grey border
convert "$filename" -bordercolor gray -border 30 -gravity South -pointsize 24 -fill orange \
-pointsize 24 -fill orange -annotate +0+2 "$file_name" "$output_file"
echo $file_name
((counter++))
current_file=0
fi
((current_file++))
done < "$files"
convert -delay 10 @"$base_dir/annotated.txt" "$base_dir/output.gif"