Skip to content

Instantly share code, notes, and snippets.

@CharStiles
Last active April 25, 2024 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CharStiles/80a5eb8ccf10eb865b5cc721cd7da3f6 to your computer and use it in GitHub Desktop.
Save CharStiles/80a5eb8ccf10eb865b5cc721cd7da3f6 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Function to generate a random hex color
generate_random_color() {
printf "%06x\n" $((RANDOM%16777215))
}
# Set the desktop directory
desktop_dir="$HOME/Desktop"
# Check if ffmpeg is installed
if ! command -v ffmpeg &> /dev/null; then
echo "Error: ffmpeg is not installed. Please install ffmpeg and try again."
exit 1
fi
# Move to desktop directory
cd "$desktop_dir" || exit
# Loop through each image file in the desktop directory
image_array=()
# Use a while loop with read to iterate over filenames
while IFS= read -r -d '' img_file; do
if [ -f "$img_file" ]; then
image_array+=("$img_file")
fi
done < <(find . -maxdepth 1 -type f \( -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.png" -o -iname "*.gif" \) -print0)
for img_file in "${image_array[@]}"; do
echo "$img_file"
done
#for x in 0.1 0.25 0.5 0.75 .99
#do
#for y in 0.1 0.25 0.5 0.75 .99
#do
# Get the length of image_array
array_length=${#image_array[@]}
# Initialize an array of numbers from 0 to array_length - 1
index_array=($(seq 0 $(($array_length - 1))))
# Shuffle the index_array
shuffled_index_array=($(shuf -e "${index_array[@]}"))
# Loop through the shuffled index_array and get image_file from image_array
for index in "${shuffled_index_array[@]}"; do
img_file="${image_array[$index]}"
destination_file="./theOnlyImageYouNeed.png"
echo "$img_file"
# Check if the image file already exists in the destination directory
if [ ! -f "$destination_file" ]; then
# If it doesn't exist, copy it to the destination directory
cp "$img_file" "$destination_file"
echo "Copied $img_file to $destination_file"
fi
# Generate random color and similarity
hex_values=("0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "a" "b" "c" "d" "e" "f")
# Generate random color
color="#"
for i in {1..6}; do
random_index=$(( RANDOM % 16 ))
color="${color}${hex_values[random_index]}"
done
similarity=0.3
blend=0.2
# Run ffmpeg command
# ffmpeg -i "$img_file" -i ./_out.png -update 1 -y -filter_complex "[0:v]scale=1280:720[scaled0];[1:v]scale=1280:720[scaled1];[scaled1]colorkey=Black:$y:$x[ckout1];[scaled0]colorkey=White:$x:$y[ckout0];[ckout0][ckout1]overlay[out]" -map "[out]" out.png
ffmpeg -i "$img_file" -i ./theOnlyImageYouNeed.png -update 1 -y -filter_complex "[0:v]scale=1280:720[scaled0];[1:v]scale=1280:720[scaled1];[scaled0]colorkey=White:0.25:0.15[ckout1];[ckout1]colorkey=Gray:0.2:0.15[ckout12];[ckout12]colorkey=$color:0.2:0.15[ckout123];[scaled1]colorkey=Black:0.25:0.215[ckout0];[ckout123][ckout0]overlay[out]" -map "[out]" out.png
# cp ./out.png "./{$img_file}_out.png"
mv ./out.png ./theOnlyImageYouNeed.png
done
#cp ./_out.png "sim{$x}blend{$y}.png"
#done
#done
echo "$shuffled_array"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment