File: compose

package info (click to toggle)
grunch 1.3-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 204 kB
  • ctags: 25
  • sloc: sh: 830; ansic: 155; perl: 91; makefile: 69
file content (87 lines) | stat: -rwxr-xr-x 2,982 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash

patchsize=64
marginsize=8
#tmp=./tmp
tmp=~/.grunch/tmp # modified for Debian
source=./final
dest=~web/html/jade-warrior/covers

titles=$(cat filelist)

count=0
rm -f $tmp/text.txt

for foo in $titles ; do
  cat $source/$foo.ttl >> $tmp/text.txt
  count=$[count+1]
done

pbmtext < $tmp/text.txt > $tmp/text.pbm

textwidth=$(pnmfile $tmp/text.pbm | awk '{print $4}')

horiz=5

hsize=$[horiz*patchsize+(horiz+3)*marginsize+textwidth]
vsize=$[count*patchsize+(count+2)*marginsize]

echo "base http://feghoot.ml.org/jade-warrior/covers/" > $tmp/composite.map

echo Making background, $hsize by $vsize

ppmmake rgb:0/0/0 $hsize $vsize > $tmp/composite.ppm

voffset=$marginsize

for foo in $titles ; do
  hoffset=$[textwidth+2*marginsize]
  pbmtext < $source/$foo.ttl | pnminvert > $tmp/text.pbm
  textheight=$(pnmfile $tmp/text.pbm | awk '{print $6}')
  insertvert=$[voffset+(patchsize-textheight)/2]
  pnmpaste -replace $tmp/text.pbm $marginsize $insertvert $tmp/composite.ppm > $tmp/newcomposite.ppm
  mv $tmp/newcomposite.ppm $tmp/composite.ppm
  for bar in A B C D E; do
    echo Processing $foo-$bar
    hlimit=$[hoffset+patchsize]
    vlimit=$[voffset+patchsize]
    if [ -f $source/$foo-$bar.tif ] ; then
      tifftopnm $source/$foo-$bar.tif | \
        pnmscale -xysize $patchsize $patchsize > $tmp/patch.pnm
      pnmpaste -replace $tmp/patch.pnm $hoffset $voffset $tmp/composite.ppm > \
        $tmp/newcomposite.ppm
      mv $tmp/newcomposite.ppm $tmp/composite.ppm
      if [ -f $dest/$foo-$bar.jpg -a $dest/$foo-$bar.jpg -nt $source/$foo-$bar.tif ] ; then
	 echo $dest/$foo-$bar.jpg exists, no need to rebuild
      else
         echo Building $dest/$foo-$bar.jpg
         tifftopnm $source/$foo-$bar.tif | \
           cjpeg -quality 90 > $dest/$foo-$bar.jpg
      fi
      echo "rect $foo-$bar.jpg $hoffset,$voffset $hlimit,$vlimit" >> $tmp/composite.map
    elif [ -f $source/$foo-$bar.gif ] ; then
      giftoppm $source/$foo-$bar.gif | \
        pnmscale -xysize $patchsize $patchsize > $tmp/patch.pnm
      pnmpaste -replace $tmp/patch.pnm $hoffset $voffset $tmp/composite.ppm > \
        $tmp/newcomposite.ppm
      mv $tmp/newcomposite.ppm $tmp/composite.ppm
      cp $source/$foo-$bar.gif $dest
      echo "rect $foo-$bar.gif $hoffset,$voffset $hlimit,$vlimit" >> $tmp/composite.map
    elif [ -f $source/$foo-$bar.jpg ] ; then
    	djpeg $source/$foo-$bar.jpg |  \
        pnmscale -xysize $patchsize $patchsize > $tmp/patch.pnm
      pnmpaste -replace $tmp/patch.pnm $hoffset $voffset $tmp/composite.ppm > \
        $tmp/newcomposite.ppm
      mv $tmp/newcomposite.ppm $tmp/composite.ppm
      cp $source/$foo-$bar.jpg $dest
      echo "rect $foo-$bar.jpg $hoffset,$voffset $hlimit,$vlimit" >> $tmp/composite.map
    else
      echo "No file available"
    fi
    hoffset=$[hoffset+patchsize+marginsize]
  done
  voffset=$[voffset+patchsize+marginsize]
done

cjpeg < $tmp/composite.ppm > $dest/composite.jpg
cp $tmp/composite.map $dest/composite.map