Opus/2024.12.07-TheThreeCalamities/image/old/i2.sh
2026-07-04 09:09:13 -07:00

74 lines
2.3 KiB
Bash
Executable File

input_file="TheThreeCalamaties-3200x1828.jpg"
output_prefix="TheThreeCalamaties"
title="The Three Calamaties"
# Check if the input file exists
if [ ! -f "$input_file" ]; then
echo "Error: File '$input_file' does not exist."
exit 1
fi
# Get dimensions of the input image
width=$(magick identify -format "%w" "$input_file")
height=$(magick identify -format "%h" "$input_file")
echo "Input file is ${width}x${height}"
###############################
# Text lines and their font sizes
line1="${title}"
line1_font_size=180
line2="www.GrailHeart.com"
line2_font_size=120
# Font
font="./Caudex-Regular.ttf" # Path to the Caudex font
# Colors to loop through
colors=("ff0000" "00FF00" "0000ff")
# Dynamically determine text image heights based on font sizes
text_height1=$((line1_font_size * 3 / 2))
text_height2=$((line2_font_size * 3 / 2))
echo "text_height1: ${text_height1}"
echo "text_height2: ${text_height2}"
# Loop through colors
for color in "${colors[@]}"; do
# Temporary text images
text_image1="_text1_${color}.png"
text_image2="_text2_${color}.png"
# Create temporary text images for each line with the current color
magick -size ${width}x${text_height1} -background none -gravity center \
-font "$font" -pointsize "$line1_font_size" -fill "#${color}" \
label:"$line1" "$text_image1"
magick -size ${width}x${text_height2} -background none -gravity center \
-font "$font" -pointsize "$line2_font_size" -fill "#${color}" \
label:"$line2" "$text_image2"
# Recalculate text heights in case padding is added by the font rendering
text_height1=$(magick identify -format "%h" "$text_image1")
text_height2=$(magick identify -format "%h" "$text_image2")
# Calculate total canvas height
canvas_height=$((height + text_height1 + text_height2 + 30))
# Output file name
output_file="${output_prefix}-${color}.png"
# Create a transparent canvas and compose the final image
magick -size ${width}x${canvas_height} xc:none \
\( "$input_file" -gravity north \) -composite \
\( "$text_image1" -gravity south -geometry +0+$((text_height2 + 20)) \) -composite \
\( "$text_image2" -gravity south -geometry +0+10 \) -composite \
"$output_file"
echo "Generated: $output_file"
# Clean up temporary text images
rm "$text_image1" "$text_image2"
done