0

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
Arcticfoxx
  • 421
  • 1
  • 5
  • 11
  • 1
    So, is `1323728291642.jpg` a valid filename for a JPEG-format image? Is it in the current directory? It seems the `identify` command is failing to open the file. – unwind Jan 17 '12 at 09:26
  • Dumb question but did you verify that 1323728291642.jpg is a valid image? i.e. what is the output of just 'identify 1323728291642.jpg'. – synthesizerpatel Jan 17 '12 at 09:28
  • yes it is vaild and in the current directory – Arcticfoxx Jan 17 '12 at 09:30
  • I got the list using `ls > ../list` – Arcticfoxx Jan 17 '12 at 09:31
  • `identify: unable to open image `1323728291642.jpg': ��� @ error/blob.c/OpenBlob/2489. identify: unable to open image `1323728291642.jpg': @ error/blob.c/OpenBlob/2489. ` yet i am 100% sure its a photo of the jpg type. – Arcticfoxx Jan 17 '12 at 09:33
  • I'll try with another image in the directory. – Arcticfoxx Jan 17 '12 at 09:34
  • just did ls grep last that first file....it doesn't exist...how is it on the list :/ – Arcticfoxx Jan 17 '12 at 09:35
  • Depending on how you're getting them, could be a temporary file that gets renamed.. etc. Instead of making a list, you could just do.. for f in $(ls *.jpg); do some_bash_function "$f"; done.. If the filename has a space in it, that'll mess things up, but you can get around that by modifying the IFS environment variable. – synthesizerpatel Jan 17 '12 at 09:38
  • 4
    @synthesizerpatel: No need to invoke `ls`. Rather than `for f in $(ls *.jpg)`, just do `for f in *.jpg` – Keith Thompson Jan 17 '12 at 10:23
  • @KeithThompson: hah! Good point, I should have reduced it down a bit more eh.. I guess I was thinking about using 'find'.. Good catch! +1 – synthesizerpatel Jan 17 '12 at 10:29

1 Answers1

0
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