BASH - math image size

446 views Asked by At

I am trying to find fractions of an image size using this

w=$(identify -format "%w" $1)
h=$(identify -format "%h" $1)
w16=$(($w/16))
w2=$(($w/2))
h16=$(($h/16))
h2=$(($h/2))

which returns this error

identify: unable to open image `1323728291642.jpg': ��� @ error/blob.c/OpenBlob/2489.
identify: unable to open image `1323728291642.jpg':  @ error/blob.c/OpenBlob/2489.
identify: unable to open image `1323728291642.jpg': �8� @ error/blob.c/OpenBlob/2489.
identify: unable to open image `1323728291642.jpg':  @ error/blob.c/OpenBlob/2489.
bash: /16: syntax error: operand expected (error token is "/16")

it was being used in this context

for i in `cat ../list`; do . ~/base64ensize.sh "$i" jpg|gpaste add;read -p "Press [Enter] key to start backup..."; done

list was a list of image files in the current directory

if needed here is the rest of base64ensize.sh

w=$(identify -format "%w" $1)
h=$(identify -format "%h" $1)
w16=$(($w/16))
w2=$(($w/2))
h16=$(($h/16))
h2=$(($h/2))
#echo $w $w2 $w15 $h $h2 $h16
echo -n "<img height='$h16' width='$w16' onclick="
echo -n '"this.height='
echo -n "'$h2';this.width='$w2'"
echo -n '" ondblclick="this.height='
echo -n "'$h16';this.width='$w16'"
echo -n '"'

echo -e "src='data:image/EXT;base64,"$(base64 $1)"'>" >> temp
sed s/"EXT"/$2/ temp
rm temp
1

There are 1 answers

0
Ярослав Рахматуллин On
for i in `cat list`; 
do  
   ./base64ensize.sh "$i" jpg |tee >(wc 1>&2 ); # use gpaste add and not wc 1>&2 here 
   read -p "Press [Enter] key to start backup..."; 
done

base64ensize.sh:

w=$(identify -format "%w" $1)
   h=$(identify -format "%h" $1)
   w16=$((w/16))
   w2=$((w/2))
   h16=$((h/16))
   h2=$((h/2))
   #echo $w $w2 $w15 $h $h2 $h16
   echo -n "<img height='$h16' width='$w16' onclick="
   echo -n '"this.height='
   echo -n "'$h2';this.width='$w2'"
   echo -n '" ondblclick="this.height='
   echo -n "'$h16';this.width='$w16'"
   echo -n '" '

   echo -e "src='data:image/$2;base64,"$(base64 -w 0 $1)"'>"
   echo
   #sed s/"EXT"/$2/ temp
   #rm temp

you may want to put the for loop into run.sh and then generte your html by:

bash run.sh > images.html