-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollage_generator.sh
executable file
·46 lines (36 loc) · 1.33 KB
/
collage_generator.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
#!/bin/bash
# Directory for output files
output_dir="./output"
# Create the output directory if it doesn't exist
mkdir -p "$output_dir"
# Initialize counter for output file names
output_counter=1
# Find all image files (both JPEG and PNG formats) in the current directory, excluding the output directory
# and read them into an array
readarray -t images < <(find . -maxdepth 1 -type f \( -name '*.jpg' -o -name '*.png' \) ! -path "./output/*" | sort)
# Process images in batches of 6
for ((i=0; i<${#images[@]}; i+=6)); do
# Select a batch of up to 6 images, handling spaces in filenames
batch=("${images[@]:i:6}")
# Check if the batch is empty
if [ ${#batch[@]} -eq 0 ]; then
break
fi
# Determine the output format based on the presence of .png files
output_format="jpg"
for img in "${batch[@]}"; do
if [[ $img == *.png ]]; then
output_format="png"
break
fi
done
# Build the montage command dynamically
montage -tile 3x2 -geometry +5+5 -background yellow "${batch[@]}" "${output_dir}/output${output_counter}.${output_format}"
# Check for errors in montage command
if [ $? -ne 0 ]; then
echo "Error: Montage command failed on batch $output_counter"
exit 1
fi
# Increment the output file counter
((output_counter++))
done