Article View: es.comp.os.linux.programacion
Article #6953Re: Script en Bash con Geomtery (ImageMagick)
From: J.A. Gutierrez
Date: Tue, 29 Apr 2003 07:38
Date: Tue, 29 Apr 2003 07:38
217 lines
5724 bytes
5724 bytes
Marco <marco@lomejordeinternet.net> wrote:
: Tengo el siguiente script para poner todas la imagenes jpg de un directorio
: en un lienzo de 250x250, pero me falla, y nu se porque. Lo qtengo echo en
: PHP, pero lo necesito para Bash, y como simepre el bash no es lo mio.
: #!/bin/sh
: for f in $* ;do
: convert -geometry 80x80 $file t_$file
: #echo "<a href=\"$f\"><img src=\"t_$f\" width=\"80\" height=\"80\"></a>"
: done
: # end of script
: Lamada al programa:
: ./programa *.jpg *.jpg
Supongamos que tienes la lista de ficheros en files.txt
(si no es asi, find -type f -name \*.jpg -print > files.txt),
y que los ficheros estan en ./normal/ y existe ./preview/
Crear previews:
---------------------------------------------------------------------------
#!/bin/ksh
while read file
do
echo $file >&2
NAME=`echo "$file" | sed -e 's/\....$//'`
if [ -f preview/$NAME.gif ]
then
:
else
convert -verbose -interlace LINE -geom 128 \
normal/$file preview/$NAME.gif 2>&1 |\
sed -e 's/\(.*\)[ ]\([0-9]*\)\(x\)\([0-9]*\)\(=>\)\([0-9]*\)\(x\)\([0-9]*\)\(.*\)/\2 \4 \6 \8/'|\
read WO HO WR HR
SO=`du -sk normal/$file | awk '{print $1}'`
SR=`du -sk preview/$NAME.gif | awk '{print $1}'`
echo $file $WO $HO $SO >> normal/idx.txt
echo $NAME.gif $WR $HR $SR >> preview/idx.txt
fi
done < files.txt
---------------------------------------------------------------------------
Crear htmls:
---------------------------------------------------------------------------
#!/bin/ksh
typeset -Z2 HN
BASE=fotos
let HN=0
let IN=0
let IR=0
NROW=2
NCOL=4
NPAGE=`expr $NROW \* $NCOL`
while read file
do
NAME=`echo "$file" | sed -e 's/\....$//'`
#egrep "^$file" originals/idx.txt | read f WO HO SO
egrep "^$file" normal/idx.txt | read f W H S
egrep "^$NAME" preview/idx.txt | read f WP HP SP
if [ $IN -eq 0 ]
then
echo "Creating new $BASE-$HN.html" >&2
cat > $BASE-$HN.html << eof
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>
<TITLE>Fotos: p�gina %PAG%</TITLE>
<meta http-equiv=Content-Type content="text/html; charset=ISO-8859-1">
<meta name=Title content="Afotos: p�gina %PAG%">
<meta name=Keywords content="fotos">
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1 ALIGN=CENTER>Fotos: p�gina %PAG%</H1>
<HR WIDTH="75%">
<center><table border=0>
eof
fi
if [ $IR -eq 0 ]
then
echo "...creating new row" >&2
cat >> $BASE-$HN.html << eof
<tr>
eof
fi
cat >> $BASE-$HN.html << eof
<TD align="center">
<A HREF="normal/$file">
<IMG SRC="preview/$NAME" ALT="$file" WIDTH="$WP" HEIGHT="$HP">
</A><BR>
<A HREF="normal/$file">
$file
<br>
${W}x${H} $S Kb
</A>
</TD>
eof
let IR=$IR+1
if [ $IR -eq $NCOL ]
then
echo "...closing row" >&2
echo '</tr>' >> $BASE-$HN.html
let IR=0
fi
let IN=$IN+1
if [ $IN -eq $NPAGE ]
then
echo "...closing html" >&2
cat >> $BASE-$HN.html << eof
</table><br>
</center>
<HR WIDTH="75%">
<p>Ir a la p�gina:
%NAV%
</p>
</BODY>
</HTML>
eof
let IN=0
let HN=$HN+1
fi
echo $file >&2
done < files.txt
if [ $IN -ne $NPAGE ]
then
echo "...closing html" >&2
cat >> $BASE-$HN.html << eof
</tr>
</table><br>
</center>
<HR WIDTH="75%">
<p>Ir a la p�gina:
%NAV%
</p>
</BODY>
</HTML>
eof
fi
if [ $IN -eq 0 ]
then
rm $BASE-$HN.html
let HN=$HN-1
fi
typeset -Z2 AHN
let I=1
let NH=$HN+1
NAV=""
while [ $I -le $NH ]
do
let AHN=$I-1
let HN=$I
NAV="${NAV}|<A HREF=\"$BASE-$AHN.html\">${HN}<\/A>"
let I=$I+1
done
let I=1
typeset -Z0 PNH
PNH=$NH
while [ $I -le $NH ]
do
let AHN=$I-1
let HN=$I
sed -e "s,\%PAG\%,$I de $PNH," \
-e "s/\%NAV\%/${NAV}|/" \
-e "s,|<A HREF=\"$BASE-$AHN.html\">${HN}<\/A>|,|${HN}|," \
$BASE-$AHN.html >> foo && mv foo $BASE-$AHN.html
let I=$I+1
done
---------------------------------------------------------------------------
Ejemplo "en vivo" del resultado:
http://phoebe.cps.unizar.es/~spd/pub/img/fotos-00.html
PS: de todas formas existen soluciones precocinadas para hacer
esto; y seguramente mas completas y faciles de usar...
--
finger spd@shiva.cps.unizar.es for PGP /
.mailcap tip of the day: / La vida es una carcel
application/ms-tnef; cat '%s' > /dev/null / con las puertas abiertas
text/x-vcard; cat '%s' > /dev/null / (A. Calamaro)
Technical Details
Message-ID:
<b8la54$rsh$1@localhost.escomposlinux.org>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!nntp.cs.ubc.ca!nntp-relay.ihug.net!ihug.co.nz!west.cox.net!cox.net!news-hub.cableinet.net!blueyonder!marmolejo.escomposlinux.org!not-for-mailReferences:
<b8l8si$av6bt$1@ID-187527.news.dfncis.de>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: f86c8,d1a4290ca0230000
X-Google-Attributes: gidf86c8,public
X-Google-ArrivalTime: 2003-04-29 00:38:15 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!nntp.cs.ubc.ca!nntp-relay.ihug.net!ihug.co.nz!west.cox.net!cox.net!news-hub.cableinet.net!blueyonder!marmolejo.escomposlinux.org!not-for-mail
From: "J.A. Gutierrez" <spd@daphne.cps.unizar.es>
Newsgroups: es.comp.os.linux.programacion
Subject: Re: Script en Bash con Geomtery (ImageMagick)
Date: Tue, 29 Apr 2003 07:38:14 +0000 (UTC)
Organization: Rank
Lines: 217
Sender: "J.A. Gutierrez" <spd@shiva.cps.unizar.es>
Message-ID: <b8la54$rsh$1@localhost.escomposlinux.org>
References: <b8l8si$av6bt$1@ID-187527.news.dfncis.de>
NNTP-Posting-Host: shiva.cps.unizar.es
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: localhost.escomposlinux.org 1051601894 28561 155.210.152.10 (29 Apr 2003 07:38:14 GMT)
X-Complaints-To: newsmaster@marmolejo.escomposlinux.org
NNTP-Posting-Date: Tue, 29 Apr 2003 07:38:14 +0000 (UTC)
User-Agent: tin/1.4.7-20030322 ("Suggestions") (UNIX) (IRIX64/6.2 (IP19))