why am I dropping the source variable value when I get into the resize_Images function?
output
script
output
Code:
[userx@FreeBSD ~]$ setupEtermImages
Enter a source path to images ~/Pictures
/home/userx/Pictures
is this the correct path? y/n y
find: : No such file or directory
script
Code:
#!/usr/bin/env bash
#Check for needed application first
[[ ! -x $(which mogrify) ]] && { echo "missing mogrify : install ImageMagick" ; exit ; }
[[ ! -x $(which unrar) ]] && { echo "missing unrar: need to install unrar" ; exit ; }
[[ ! -x $(which zip) ]] && { echo "missing zip: need to install a zip program" ; exit ; }
#Gets Monitor Dimensions for
#knowing what size to make images
getdimensions=$( xdpyinfo | grep dimensions | awk '{print $2}' )
#split the width and height into separate variables.
screenwidth=${getdimensions%x*}
screenheight=${getdimensions#*x}
#desired image width
width=$screenwidth
source=
destanation=
flag=false
while [[ $flag = 'false' ]]
do
if [[ -z $imagePath ]] ;
then
read -p "Enter a source path to images " imagePath
fi
#to expand the tidle mark to users home dir
[[ $imagePath =~ '~' ]] && { imagePath=${imagePath/#\~/$HOME} ; }
read -p "
$imagePath
is this the correct path? y/n " ans1
case $ans1 in
'y'|'Y')
flag=true ;;
'n'|'N')
flag=false
imagePath='' ;;
esac
done
resize_Images()
{
while read f
do
wh=$(identify -format "%wx%h" "$f")
if [[ ${wh%x*} -gt ${wh#*x} ]] ; then
{
#wide images
[[ $(identify -format "%[fx:w]" "$f") -gt "$width" ]] &&
{ mogrify -resize "$width" "$f" ;
echo " $f" ;
size=$( identify -format "%wx%h" $f) ; }
}
else
{
#tall images if not wide then it is tall so just resize
#image if needed
[[ $(identify -format "%[fx:h]" "$f") -gt "$screenheight" ]] &&
{ mogrify -geometry x"$screenheight" "$f" ;
echo " $f" ;
size=$( identify -format "%wx%h" $f) ; }
}
fi
echo $wh
echo $size
done < <(find "$source" \( -type f -iname "*.jpg" -o -type f -iname "*.png" \) )
}
[[ $flag = 'true' ]] && resize_Images