logo atc

Promouvoir et soutenir le logiciel libre

Calendrier

November 2005
M T W T F S S
    Feb »
 123456
78910111213
14151617181920
21222324252627
282930  

17 November 2005

Modifier la taille d’images

Voici un script pour :

  • Modifier la taille d’images
  • Créer des pages html contenant les images modifiées et des liens pour les images originales

Bref un petit diaporama simple à mettre en place. Les instructions sont à l’intérieur du code.

  • Copiez le code dans un fichier et enregistrez le
  • Donnez au fichier les droits 755.
  • Copiez le fichier dans le dossier contenant les images (faites en sorte que les image est la même orientation et le même rapport hauteur/largeur pour respecter les proportions).
  • Faites en sorte que le titre des images ne contienne pas d’espace. Il y a sur le site un petit script permettant de régler ce problème.
  • exectutez le script.


#!/bin/sh

# ~~~~~~~~ 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: usergroup at alcatorda dot com

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 < thumbnail_multipage -- generate W3 compliant html pages with thumbnails to click on for a number of images.
USAGE: thumb [-h] [ -W width] [-H height] [-N name_of_html_page] [-n number_of_image_per_page] path/image1 image2 ...
OPTIONS: -h this help.
EXAMPLE: thumb -W 120 -H 80 -N page -n 6 image1 image2
EXAMPLE: thumb -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
"http://www.w3.org/TR/html4/loose.dtd">














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”
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”
cat >> $filename < < EOF

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 “Back” >> $filename ;
fi
number=`expr $number + 1`
i=0
footer;
filename=$filename2
title=$title2
header;
fi
fi

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



[$bn]

EOF
modulo=`expr $i % 3`
if [ “$modulo” = “0″ ]; then
cat >> $filename < < EOF
${array[0]} ${array[1]} ${array[2]}

$title2

src="http://www.w3.org/Icons/valid-html401"
alt="Valid HTML 4.01!" height="31" width="88"/>



EOF
}

done
footer

• • •
Powered by: WordPress • Шаблон: ADMIN-BG