136 lines
4.0 KiB
Bash
Executable File
136 lines
4.0 KiB
Bash
Executable File
#!/bin/bash
|
|
# Printify and woocommerce images
|
|
|
|
# Check if two arguments are provided
|
|
if [ $# -ne 3 ]; then
|
|
echo "Usage: $0 <input_file> <output_prefix> <title>"
|
|
exit 1
|
|
fi
|
|
|
|
#input_file="TheThreeCalamaties-3200x1828.jpg"
|
|
#output_prefix="TheThreeCalamaties"
|
|
#title="The Three Calamaties"
|
|
|
|
# Assign arguments to variables
|
|
input_file="$1"
|
|
output_prefix="$2"
|
|
title="$3"
|
|
|
|
# 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
|
|
input_width=$(magick identify -format "%w" "$input_file")
|
|
input_height=$(magick identify -format "%h" "$input_file")
|
|
input_dimension="${input_width}x${input_height}px"
|
|
|
|
echo "Input file is ${input_dimension}"
|
|
|
|
##################
|
|
# Make upscaled version
|
|
API_KEY="36d8624a99dd4ff2b9bddb7f52c48a15"
|
|
output_file="${output_prefix}-${input_dimensions}.jpg"
|
|
|
|
response=$(curl \
|
|
-F "image=@${input_file}" \
|
|
-H "api-key: eca50643-c007-462a-ab9c-a635a9c335e6" \
|
|
https://api.deepai.org/api/torch-srgan)
|
|
|
|
# Step 2: Parse the output URL from the response
|
|
output_url=$(echo "$response" | grep -oP '(?<="output_url": ")[^"]*')
|
|
|
|
# Step 3: Check if the URL was retrieved
|
|
if [ -z "$output_url" ]; then
|
|
echo "Error: Unable to retrieve the output URL."
|
|
echo "Response: $response"
|
|
exit 1
|
|
fi
|
|
|
|
#echo "Upscaled image URL: $output_url"
|
|
|
|
# Step 4: Download the upscaled image
|
|
temp_file="_____.jpg"
|
|
curl -s -o "${temp_file}" "${output_url}"
|
|
if [ $? -ne 0 ]; then
|
|
echo "ERROR: failed to download the upscaled image."
|
|
exit 1
|
|
fi
|
|
output_dimension=$(magick identify -format "%wx%h" "${temp_file}")
|
|
large_output_file="${output_prefix}-${output_dimension}.jpg"
|
|
mv "${temp_file}" "${large_output_file}"
|
|
|
|
echo "Upscaled image saved as ${large_output_file}"
|
|
large_width=$(magick identify -format "%w" "$large_output_file")
|
|
large_height=$(magick identify -format "%h" "$large_output_file")
|
|
|
|
###############################
|
|
# Create text pngs
|
|
|
|
# Text lines and their font sizes
|
|
line1="${title}"
|
|
line1_font_size=180
|
|
line1_padding=20 # Padding for line 1 (top padding in pixels)
|
|
|
|
line2="www.GrailHeart.com"
|
|
line2_font_size=120
|
|
line2_padding=30 # Padding for line 2 (top padding in pixels)
|
|
|
|
# Font
|
|
font="./Caudex-Regular.ttf" # Path to the Caudex font
|
|
|
|
# List of colors: (Human Name, Hex Code)
|
|
colors=(
|
|
"Ivory=fbefbf"
|
|
"Burgundy=400004"
|
|
"Charcoal=101417"
|
|
"Black=000000"
|
|
)
|
|
|
|
# Loop through colors
|
|
for color_entry in "${colors[@]}"; do
|
|
# Extract human-readable name and hex code
|
|
color_name="${color_entry%=*}" # Everything before '='
|
|
color_hex="${color_entry#*=}" # Everything after '='
|
|
|
|
# Temporary text images
|
|
text_image1="_text1_${color_name}.png"
|
|
text_image2="_text2_${color_name}.png"
|
|
|
|
# Create temporary text images for each line with the current color
|
|
magick -background none -gravity center \
|
|
-font "$font" -pointsize "$line1_font_size" -fill "#${color_hex}" \
|
|
label:"$line1" -trim +repage \
|
|
-gravity north -splice 0x${line1_padding} "$text_image1"
|
|
|
|
magick -background none -gravity center \
|
|
-font "$font" -pointsize "$line2_font_size" -fill "#${color_hex}" \
|
|
label:"$line2" -trim +repage \
|
|
-gravity north -splice 0x${line2_padding} "$text_image2"
|
|
|
|
# Get the adjusted dimensions of the text images
|
|
text_height1=$(magick identify -format "%h" "$text_image1")
|
|
text_height2=$(magick identify -format "%h" "$text_image2")
|
|
|
|
# Calculate total canvas height
|
|
canvas_height=$((large_height + text_height1 + text_height2 + 50))
|
|
|
|
# Output file name
|
|
output_file="${output_prefix}-${output_dimension}-${color_name}.png"
|
|
|
|
# Create a transparent canvas and compose the final image
|
|
magick -size ${large_width}x${canvas_height} xc:none \
|
|
\( "$large_output_file" -gravity north \) -composite \
|
|
\( "$text_image1" -gravity north -geometry +0+$((large_height + 10)) \) -composite \
|
|
\( "$text_image2" -gravity north -geometry +0+$((large_height + text_height1 + 20)) \) -composite \
|
|
"$output_file"
|
|
|
|
echo "Generated: $output_file"
|
|
|
|
# Clean up temporary text images
|
|
rm "$text_image1" "$text_image2"
|
|
done
|
|
|