[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: des outils qui changent la vie



faire des pages web avec images (organiser les images dans des dossiers par orientation portrait/paysage)

#!/bin/bash

# ~~~~~~~~ original credit ~~~~~~~~~~~~~
#vim: set sw=4 ts=4 et:
# wirtten by katja socher <katja@linuxfocus.org>
# and guido socher <guido@linuxfocus.org>
# ~~~~~~ end original credit ~~~~~~~~~~~

# I found the file at
# http://linuxfocus.org/English/July2001/article211.shtml

# the file has been heavily modified by myself
# to be able to create w3 compliant html page

# this is my first bash script, don't hesitate to email me
# any error or improvement

# Philippe Rousselot Aug. 2002,  EMail: linux at rousselot dot org


ver="1.0";
one=1;
number=1;
extension=".html";
page_numb=1 ;
j=0;
array=("" "" "");

test()
{
case $page_numb in
   1) page_numb="01"  ;;
   2) page_numb="02"  ;;
   3) page_numb="03"  ;;
   4) page_numb="04"  ;;
   5) page_numb="05"  ;;
   6) page_numb="06"  ;;
   7) page_numb="07"  ;;
   8) page_numb="08"  ;;
   9) page_numb="09"  ;;

esac
}

help()
{
cat <<HELP
   thumbnail_multipage -- generate W3 compliant html pages with thumbnails
to click on for a number of images.
   USAGE: htmlthumbnails [-h] [ -W width] [-H height] [-N
name_of_html_page] [-n number_of_image_per_page] path/image1 image2 ...
   OPTIONS: -h this help.
   EXAMPLE: htmlthumbnails -W 120 -H 80 -N page -n 6 image1 image2
   EXAMPLE: htmlthumbnails -W 80 -H 120 -N page -n 6 ~/images/*.jpeg
   The html code is written to files called
name_of_html_page_file_number.html.
   I recommend leaving the script always in the same folder and using the
absolute path for the images (~/path/image).
   All thumbnails have a size of widthxheight.
   Make sure you use the right orientation.

   This script requires ImageMagick

   if you modify the script, make sure the html file still validates as
HTML 4.01 Transitional!

   version $ver
HELP
exit 0
}


error()
{
   echo "$1"
   exit "$2"

}

header()
{
   #creates header for html page
   cat > $filename << EOF
   <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
           "http://www.w3.org/TR/html4/loose.dtd";>

   <html>
           <head>

                   <meta HTTP-EQUIV="Content-Type" CONTENT="text/html;
charset=ISO-8859-1">
                   <meta name="Author" LANG="fr" CONTENT="">
                   <meta name="Description" CONTENT="Page created with
thumbnail_multipage">
                   <meta name="Description" CONTENT="">
                   <meta name="Keywords" LANG="fr" CONTENT="">
                   <meta name="Identifier-URL" CONTENT="http://";>
                   <meta name="Reply-to" CONTENT="">
                   <meta name="revisit-after" CONTENT="31">
                   <meta name="Publisher" CONTENT="Quanta Plus">
                   <meta name="Copyright" CONTENT="">
                   <meta name="date" CONTENT="2002-07-06">
                   <meta name="Generator" CONTENT="Quanta plus, gFTP">

                        <title>   "$title"    </title>

                   <style type="text/css">
                   </style>

           </head>
           <body>

                <table border =" 0" align="center" width ="500">
                        <tr align="center">




EOF
}


footer()
{
   cat >> $filename << EOF

                        <td></td><td>
                                <!-- link for ./$title2 -->
                                <a href="./$title2">$title2</a>
                        </td><td></td>
                </tr>
        </table>

        <br>


           <p>
<a href="http://validator.w3.org/check/referer";><img border="0"
                    src="http://www.w3.org/Icons/valid-html401";
                    alt="Valid HTML 4.01!" height="31" width="88"></a>
              </p>

           </body>

   </html>
EOF
}

while [ -n "$1" ];
do
 case $1 in
   -h) help;shift 1;;
   --) break;;
   -W) width=$2; break;;
   -H) echo "wrong argument. It should be -W";exit 1;;
   -N) echo "wrong argument. It should be -W";exit 1;;
   -n) echo "wrong argument. It should be -W";exit 1;;
   -*) echo "error: no such option $1. -h for help";exit 1;;
   *)  break;;
   esac
done

while [ -n "$3" ];
do
 case $3 in
   -h) help;shift 1;;
   --) break;;
   -W) echo "wrong argument. It should be -H";exit 1;;
   -H) height=$4 ;break;;
   -N) echo "wrong argument. It should be -H";exit 1;;
   -n) echo "wrong argument. It should be -H";exit 1;;
   -*) echo "error: no such option $1. -h for help";exit 1;;
   *)  break;;
   esac
done

while [ -n "$5" ];
do
 case $5 in
   -h) help;shift 1;;
   --) break;;
   -W) echo "wrong argument. It should be -N";exit 1;;
   -H) echo "wrong argument. It should be -N";exit 1;;
   -N) name=$6 ; break;;
   -n) echo "wrong argument. It should be -N";exit 1;;
   -*) echo "error: no such option $1. -h for help";exit 1;;
   *)  break;;
   esac
done

while [ -n "$7" ];
do
 case $7 in
   -h) help;shift 1;;
   --) break;;
   -W) echo "wrong argument. It should be -n";exit 1;;
   -H) echo "wrong argument. It should be -n";exit 1;;
   -N) echo "wrong argument. It should be -n";exit 1;;
   -n) quota=$8 ; break;;
   -*) echo "error: no such option $1. -h for help";exit 1;;
   *)  break;;
   esac
done

dirname_image=`dirname "$9"`
th="thumbnails"
#ftp="ftp://.../images/";
ftp="."
thumbnail_dir="$dirname_image/$th"
test
filename="$dirname_image/$name$page_numb$extension";
title="$name$page_numb$extension";
mkdir "$thumbnail_dir"


if [ -z "$9" ];then
    error "No image specified, -h for help" 1
fi

# process each image
i=0;

header;

shift 8

for image in $* ;
do
   echo "$image"
    if [ ! -r "$image" ]; then
        echo "ERROR: can not read $image\n"
    else
        i=`expr $i + 1`
        bn=`basename "$image"`
        array[j]=$bn

        j=`expr $j + 1`
        thumbnail="$thumbnail_dir/t_$bn"

        convert -geometry "${width}x$height" "$image" "$thumbnail"

#mettre demande de légende ici
legend="mettre légende ici";

        cat >> $filename << EOF

        <td>
                <!-- image nr $i -->
                <a href="$ftp/$bn" name="$bn" type="image/jpeg">
                        <img src="./$th/t_$bn" width="$width"
height="$height" alt="[$bn]" border=1 title="$legend">
                </a>
        </td>
EOF
   modulo=`expr $i % 3`


        if [ "$modulo" = "0" ]; then
           cat >> $filename << EOF
           </tr>
           <tr align="center">
                <td>
                        ${array[0]}
                </td>
                <td>
                        ${array[1]}
                </td>
                <td>
                        ${array[2]}
                </td>
           </tr>
           <tr align="center">
                <td>
                        <br>
                </td>
                <td>
                        <br>
                </td>
                <td>
                        <br>
                </td>
           </tr>
           <tr align=center>
EOF
            j=0
            array=('' '' '')
        fi

   modulo=`expr $i % $quota`


   if [ "$modulo" = "0" ]; then

           page_numb=`expr $page_numb + 1`;
       test
       filename2="$dirname_image/$name$page_numb$extension";
       title2="$name$page_numb$extension";

       if [ "$number" -ne "$one" ]; then
echo "<a href=\"javascript:history.back()\">Back</a>" >> $filename ;
       fi


       number=`expr $number + 1`
       i=0
       footer;
       filename=$filename2
       title=$title2

       header;
        fi

    fi
done
footer


Reply to: