Saturday 30 September 2023

Xor everything - script to use gmic displacement on multiple images

 




A script to use gmic to displace adjacent images in a folder and output into a second folder - should work on Linux and Windows ( using git-bash and downloading gmic cli and placing it in the C:\Program Files\Git\usr\bin directory) . Copy script into notepad ++ and save as file with .sh extension. It also handily resizes all images to the same size before operating the gmic function.

#! /bin/bash
#make directory to hold output
h=$(pwd)
echo $h
#make folder to store originals
mkdir $h/originals
mkdir $h/frames
p=$(date +%Y-%m-%d_%H%M%S)
mkdir $p
echo -n "Source image format ? : "
read f
#copy originals to $h/originals
cp *.$f $h/originals/
#randomise
echo -n "Randomise ? (y/n) : "
read rn
if [ $rn == "y" ] || [ $rn == "null" ]
          then
          find . -maxdepth 1 -name '*.'$f''|while read filename; do echo ${filename}; mv ${filename} ${RANDOM}.$f; done  
          elif [ $rn == "n" ]
           then
           echo -n "Not randomising"
           fi
                     
#get dimensions
echo -n "Landscape(l),square(s),portrait(p)? : "
read lsp
#modify to size depending lsp variable
if [ $lsp == "s" ] || [ $lsp == "null" ]
          then   
          mogrify -resize 800x800! *.$f      
             
           elif [ $lsp == "l" ]
           then
           mogrify -resize 800x600! *.$f
           elif [ $lsp == "p" ]
           then
           mogrify -resize 600x800! *.$f
          
           fi
i=$(ls *.$f | wc -l)
echo $i
while [ $i -gt 0 ]
do
#move 2 files to $h/frames with find
find . -maxdepth 1 -name '*.'$f'' | head -n 2 | xargs -d $'\n' mv -t $h/frames/

#move to frames directory
cd $h/frames/
z=1
#rename files to swap1 and swap2
find . -maxdepth 1 -type f -name '*.'$f''|while read filename; do echo ${filename};
mv ${filename} swap$z.$f
((z++));
done
gmic swap1.$f swap2.$f  -blend xor -o swap3.$f
d=$(date +%Y-%m-%d_%H%M%S)
mv swap3.$f $h/$p/$d.$f
sleep 1
rm swap1.$f
rm swap2.$f
cd $h
i=$((i-=2))
done



ikillerpulse ( requires tomato.py in working directory)

I've been working on this script for the last week or so. What does it do? It takes an input video/s,  converts to a format we can use f...