Skip to content

Instantly share code, notes, and snippets.

@bjornpagen
Last active February 17, 2023 07:37
Show Gist options
  • Save bjornpagen/ff50a498788077c29d3df540ac2dc799 to your computer and use it in GitHub Desktop.
Save bjornpagen/ff50a498788077c29d3df540ac2dc799 to your computer and use it in GitHub Desktop.
A Really Terrible Image Randomizer - uses exiftool and imgmagick
#!/bin/bash
mkdir imgs
res=()
for lhs in -1 1
do
for rhs in $(seq -w 0 99)
do
res+=("${lhs}.${rhs}")
done
done
res=("${res[@]:1}")
i=1
for n in "${res[@]}"
do
for m in "${res[@]}"
do
file="imgs/${1}n${n}x${m}.png"
convert $1 -brightness-contrast "${n}x${m}" "${file}.1"
random0to9=$((RANDOM%10))
random0to9999=$((RANDOM%10000))
angle="${random0to9}.${random0to9999}"
ratio=`convert ${file}.1 -format "%[fx:aa=$angle*pi/180; min(w,h)/(w*abs(cos(aa))+h*abs(sin(aa)))]" info:`
crop="%[fx:floor(w*$ratio)]x%[fx:floor(h*$ratio)]"
crop="$crop+%[fx:ceil((w-w*$ratio)/2)]+%[fx:ceil((h-h*$ratio)/2)]"
convert "${file}.1" -set option:distort:viewport "$crop" +distort SRT $angle +repage "${file}.2"
random0to9=$((RANDOM%10))
random0to9999=$((RANDOM%10000))
convert "${file}.2" -adaptive-sharpen "${random0to9}.${random0to9999}" "${file}.3"
random0to9=$((RANDOM%10))
random0to9999=$((RANDOM%10000))
convert "${file}.3" -fill red -colorize "0.${random0to9999}" "${file}.4"
random0to9999=$((RANDOM%10000))
convert "${file}.4" -swirl "0.${random0to9999}" "${file}"
exiftool -all= "${file}"
i=$((i+1))
if [ $2 -lt ${i} ]
then
rm imgs/*original
rm imgs/*.1
rm imgs/*.2
rm imgs/*.3
rm imgs/*.4
exit 0
fi
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment