#!/bin/bash # #   Author: Heir!1APPARENTs (aka TeaL) # #   This script is expecting to run in GNU BASH version 3.2 or later, and is also #   dependent on the 'convert', and 'identify' programs from the Imagemagick package, #   aswell as the 'bc' arbitrary precision calculator language. # #   You must make sure 'convert', and 'identify' are in $PATH, and that you run this script in the #   same directory as the image you plan to use. A 'bc' package should already be included in any POSIX #   compliant system. If you plan to run this in cygwin you will need to install 'bc' aswell. # #   Run by: bash makeAv0.3.sh #   Older versions could run via /bin/sh which is usually a link to dash, not BASH (as I discovered). #   BASH is now required to run, so use the above method to run the script rather than sh makeAv0.3.sh. # #   This program is free software: you can redistribute it and/or modify #   it under the terms of the GNU General Public License as published by #   the Free Software Foundation, either version 3 of the License, or #   (at your option) any later version.   #   This program is distributed in the hope that it will be useful, #   but WITHOUT ANY WARRANTY; without even the implied warranty of #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the #   GNU General Public License for more details. # reSizeAll() {   xres=$1 yres=$2 renmask=$3 exten=$4 #Making the variable names friendly.   echo "Re-sizing ... This could take a long time.." convert "_"$renmask* -resize $(($xres))x$(($yres))! $renmask"."$exten #Re-sizing all images in $PWD that begin with $renmask to the dimensions of the original image.   echo "Done re-sizing, removing all old images.. last chance to pull the plug on it ctrl c .." sleep 5 rm "_"$renmask* #Removing the old images. }   reSize() {   i=0 o=0 count=0 #Integers to be incremented, helps to get around nesting while loops, which BASH doesn't like.   max=$1 xres=$2 yres=$3 picname=$4 renmask=$5 exten=$6 count2=$(( ($max*$max) + 1)) #Re-writing the passed variables to more friendly names, making a separate counter for opposite operation images.   while [ $count -le $(($max*$max)) ]   do           if [ $i = $max ]; then                 o=$(($o+1))                 i=0;         fi;                 convert $picname"."$exten -resize $(($xres - $i))x$(($yres - $o))! "_"$renmask$count"."$exten         convert $picname"."$exten -resize $(($xres + $i))x$(($yres + $o))! "_"$renmask$count2"."$exten                 i=$(($i+1))         count=$(($count+1));         count2=$(($count2+1));   done #Creates new images that are different by up to $max in the x and y, naming them with their iteration number and mask. }   printf "This script will make very similar images, it will do so by re-sizing the original by pixels at a time, then re-sizing them back to the original dimensions. This relies on the data lost / created in the initial re-sizes. \nThis will create MANY new images, so you may want to run it in a new directory (folder).\n\n" echo "Name of the picture.. NO EXTENSION (no .jpg, .png etc)" read picname echo "Alright, how many images do you want to make (I will make close to this number)" read numpics   max=$(echo "scale=0; sqrt ( $(echo "scale=0; $numpics / 2" | bc -l) )" | bc -l) #Using bc to determine the number of pixels to move based on the number of images requested.   exten=$(identify -format "%e" $picname"."*) #Using identify to read the format of the image.   xres=$(identify -format "%[fx:w]" $picname"."$exten) yres=$(identify -format "%[fx:h]" $picname"."$exten) #Using 'identify' to get the x and y resolution of the image.   printf "Now the renaming mask, the new pictues will all have this name and a number. Make sure nothing else is following this pattern.\n" read renmask   printf "This could take some time to finish...\n\n"   reSize $max $xres $yres $picname $renmask $exten   printf "Should be done making the new images.. Just have to re-size them...\n\n\n" printf "If you made hundreds of images, or used very large ones, this could get messy, as 'convert' buffers, meaning it will chew up a bunch of system memory. If you don't have enough memory, your computer may slow.\n\n" printf "This will re-size (making a copy of) every image I created (_$renmask *), then delete the old ones.\n\n" echo "Are you sure you want to continue? yes / no.." read ans   if [[ "$ans" = *y* ]]; then         reSizeAll $xres $yres $renmask $exten         elif [[ "$ans" = *n* ]]; then         echo "exiting.."         exit else         echo "invalid option, must contain a 'y' or 'n'.. exiting"         exit fi;   echo "All done.." exit