Repository navigation
Expand file tree
/
Copy pathmkheadshot.sh
More file actions
executable file
·68 lines (57 loc) · 2.09 KB
/
Copy pathmkheadshot.sh
File metadata and controls
executable file
·68 lines (57 loc) · 2.09 KB
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
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env bash
show_help() {
echo "Usage: $0 [input_dir] [gravity] [offset]"
echo ""
echo "Parameters:"
echo " input_dir Directory containing the input images (default: ./input)"
echo " gravity Gravity setting for ImageMagick operations (default: center)"
echo " offset Offset setting for ImageMagick operations (default: +0+0)"
echo ""
echo "Examples:"
echo " $0"
echo " $0 my_input_directory north +0+10"
}
# Check for help argument or if input_dir does not exist
if [[ "$1" == "help" || "$1" == "-help" || "$1" == "--help" || "$1" == "-?" ]]; then
show_help
exit 0
fi
# Set the parameters with default values if not provided
input_dir=${1:-input}
gravity=${2:-center}
offset=${3:-+0+0}
if [[ ! -d "$input_dir" ]]; then
echo "Error: Input directory '$input_dir' does not exist."
show_help
exit 1
fi
# Ensure the required directories exist
mkdir -p normalized tessellated
# Check if there are files to process
shopt -s nullglob
input_files=("$input_dir"/*)
if [[ ${#input_files[@]} -eq 0 ]]; then
echo "No files to process in directory '$input_dir'."
show_help
exit 1
fi
shopt -u nullglob
# Iterate over each input file in the input directory
for input_file in "${input_files[@]}"; do
# Get the base name and extension
base_name=$(basename "$input_file")
extension="${base_name##*.}"
base_name="${base_name%.*}"
output_name="$base_name.png"
# Transform the headshot
normalized_file="normalized/${base_name}__384x512.png"
convert "$input_file" -auto-orient -resize "384^x512" -flatten -gravity "$gravity" -crop 384^x512"$offset" +repage "$normalized_file"
# Combine the tessellation with the normalized headshot
tessellated_file="tessellated/${base_name}__tessellated.png"
montage -mode concatenate tess.png "$normalized_file" -tile 2x1 -geometry +0+0 "$tessellated_file"
# Display info about the images
identify "$normalized_file"
identify "$tessellated_file"
# Optionally, open the tessellated image (comment this out if not needed)
open "$tessellated_file"
done