-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlens_assembler.sh
More file actions
102 lines (88 loc) · 2.94 KB
/
lens_assembler.sh
File metadata and controls
102 lines (88 loc) · 2.94 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/bash
# ==============================================================================
# Script: dual_cam.sh (Final, Reliable Version)
# FIX: Restored multi-line structure with minimal, correct parenthesis escaping.
# Added diagnostic checks for input file paths.
# ==============================================================================
# Default settings
POSITION="SouthEast"
SCALE=20
OUTPUT="output.png"
BORDER_WIDTH=4
PADDING=40
# --- Function to display help (omitted for brevity, but remains in your file) ---
# --- Argument Parsing (unchanged) ---
while getopts "b:a:p:o:s:h" opt; do
case ${opt} in
b) BG="$OPTARG" ;;
a) AVATAR="$OPTARG" ;;
p)
case "$OPTARG" in
tr) POSITION="NorthEast" ;;
tl) POSITION="NorthWest" ;;
br) POSITION="SouthEast" ;;
bl) POSITION="SouthWest" ;;
*) POSITION="SouthEast" ;;
esac
;;
o) OUTPUT="$OPTARG" ;;
s) SCALE="$OPTARG" ;;
h) exit 1 ;;
*) exit 1 ;;
esac
done
# --- Validation and Diagnostic Checks ---
if ! command -v magick &> /dev/null; then
echo "Error: ImageMagick ('magick') is not installed."
exit 1
fi
if [[ -z "$BG" || -z "$AVATAR" ]]; then
echo "Error: You must provide both a background (-b) and an avatar (-a)."
exit 1
fi
# New Diagnostic Check
if [[ ! -f "$BG" ]]; then
echo "CRITICAL ERROR: Background file '$BG' not found."
exit 1
fi
if [[ ! -f "$AVATAR" ]]; then
echo "CRITICAL ERROR: Avatar file '$AVATAR' not found."
exit 1
fi
# --- Core Logic ---
if ! BG_W=$(magick identify -format "%w" "$BG" 2>/dev/null); then
echo "Error: Could not read width of background image '$BG'. Check file integrity."
exit 1
fi
SIZE=$(( BG_W * SCALE / 100 ))
RADIUS=$(( SIZE / 2 ))
echo "--- Image Composition ---"
echo "Reading background: $BG"
echo "Reading avatar: $AVATAR"
echo "Calculated Avatar Size: ${SIZE}px (${SCALE}%)"
# 2. ImageMagick Processing Chain - MINIMAL, CORRECT ESCAPING
# STEP 1: Resize and Square the Avatar
magick "$AVATAR" \
-resize "${SIZE}x${SIZE}^" \
-gravity center \
-extent "${SIZE}x${SIZE}" \
temp_avatar_square.png
# STEP 2: Apply Circular Mask and Set Transparent Background
magick temp_avatar_square.png \
-alpha set -background none \
\( +clone -alpha transparent -draw "circle ${RADIUS},${RADIUS} ${RADIUS},0" \) \
-compose DstIn -composite \
temp_avatar_circular.png
# STEP 3: Add Border and Shadow
magick temp_avatar_circular.png \
\( +clone -background black \) \
+swap -background none -layers merge +repage \
temp_avatar_final_block.png
# STEP 4: Composite the Final Image
magick "$BG" temp_avatar_final_block.png \
-gravity "$POSITION" \
-geometry +${PADDING}+${PADDING} \
-compose over -composite \
"$OUTPUT"
echo "-------------------------"
echo "Success! The dual-camera image has been created and saved to $OUTPUT."