From: arno Date: Wed, 5 Aug 2009 20:10:02 +0000 (+0200) Subject: create thumbnails of photos X-Git-Tag: v0.2~13 X-Git-Url: https://dev.renevier.net/gitweb.cgi?p=syp.git;a=commitdiff_plain;h=9acc365249b5e630da6b5cdd23e3a8015f39ddc7 create thumbnails of photos --- diff --git a/README.txt b/README.txt index d648c63..3394938 100644 --- a/README.txt +++ b/README.txt @@ -14,10 +14,20 @@ Requirements Installation ------------ +upload syp to your webserver edit inc/settings.php -open http://yoururl.com/wizard.php +open http://yoururl.com/wizard.php with your web browser follow instructions +Upgrade +------------ +- make a copy of inc/settings.php +- delete old version of syp from your server +- upload now version +- edit inc/settings.php again (copy old version of file may not be enough + because new settings may have appeared) +- open http://yoururl.com/upgrade.php with your web browser + server API ---------- The way server side communicates with client side is described at diff --git a/api.php b/api.php index 39c6319..18c7179 100644 --- a/api.php +++ b/api.php @@ -20,7 +20,7 @@ function success_feature ($feature, $request) { $res .= "" . ($feature->imgpath ? - full_url_from_imgpath ($feature->imgpath) + image_url_from_imgpath ($feature->imgpath) : "") . ""; @@ -98,6 +98,19 @@ function save_uploaded_file ($file, $con) { (!move_uploaded_file ($file ["tmp_name"], $dest))) { server_error (); } + $mini_dest = getthumbsdir () . "/mini_" . basename_safe ($dest); + + try { + $thumbnail_ok = create_thumbnail ($dest, $mini_dest); + } catch (Exception $e) { + $thumbnail_ok = false; + } + if (!$thumbnail_ok) { + if (!copy ($dest, $mini_dest)) { + server_error (); + } + } + } return basename_safe ($dest); } @@ -120,14 +133,17 @@ function delete_image_if_unused ($imgpath, $con) { return; } if ($con->imgpath_exists ($imgpath)) { - return false; + return; } + $path = UPLOADDIR . "/" . $imgpath; - if (file_exists($path)) { + if (file_exists ($path)) { unlink ($path); - return true; - } else { - return false; + } + + $thumb_path = getthumbsdir () . "/mini_" . $imgpath; + if (file_exists ($thumb_path)) { + unlink ($thumb_path); } } diff --git a/build.sh b/build.sh index d6c6a28..764f1c6 100755 --- a/build.sh +++ b/build.sh @@ -15,7 +15,7 @@ mkdir -p $DESTDIR cp -RLp inc/ $DESTDIR/ # other php files -cp -p admin.*php index.*php wizard.*php news.php api.php items.php logout.php $DESTDIR/ +cp -p admin.*php index.*php upgrade.*php wizard.*php news.php api.php items.php logout.php $DESTDIR/ # media cp -RLp media/ $DESTDIR/ @@ -61,8 +61,8 @@ done cp -p license.txt README.txt COPYING.txt $DESTDIR/ # creates upload directory -mkdir $DESTDIR/upload -chmod a+wx $DESTDIR/upload +mkdir -p $DESTDIR/upload/_thumbs +chmod -R a+wx $DESTDIR/upload # generate sources cd $BUILDDIR diff --git a/inc/i10n/en/syp.php b/inc/i10n/en/syp.php index 4d965ea..3bf57b9 100644 --- a/inc/i10n/en/syp.php +++ b/inc/i10n/en/syp.php @@ -17,6 +17,18 @@ "SYP wizard" => "", + "exist but is not a directory" + => "", + + "could not create directory" + => "", + + "directory created" + => "", + + "could not write in directory" + => "", + "You need at least PHP version 5" => "", @@ -65,19 +77,22 @@ "Data table created." => "", - "exist but is not a directory" + "It looks like GD extension is not installed." => "", - "could not create directory" + "SYP is installed. You can now go to admin area" => "", - "directory created" + "SYP upgrade" => "", - "could not write in directory" + "Thumbnails successfully created." => "", - "SYP is installed. You can now go to admin area" + "Error when creating thumbnails." + => "", + + "SYP upgrade went smoothly. You can now go to admin area" => "", "SYP needs javascript. Please activate scripts in your browser." diff --git a/inc/i10n/fr/syp.php b/inc/i10n/fr/syp.php index 9b1f815..0ebe330 100644 --- a/inc/i10n/fr/syp.php +++ b/inc/i10n/fr/syp.php @@ -18,6 +18,26 @@ "Assistant d'installation de SYP" , + "exist but is not a directory" + => + "existe mais n'est pas un répertoire" + , + + "could not create directory" + => + "Impossible de créer le répertoire" + , + + "directory created" + => + "Répertoire créé" + , + + "could not write in directory" + => + "Impossible d'écrire dans le répertoire" + , + "You need at least PHP version 5" => "Vous devez utiliser une version de PHP au moins égale à la version 5" @@ -98,29 +118,34 @@ "Table des données créée." , - "exist but is not a directory" + "It looks like GD extension is not installed." => - "existe mais n'est pas un répertoire" + "L'extension GD ne semble pas être installée." , - "could not create directory" + "SYP is installed. You can now go to admin area" => - "Impossible de créer le répertoire" + "SYP est installé. Vous pouvez maintenant vous rendre dans la partie administration." , - "directory created" + "SYP upgrade" => - "Répertoire créé" + "mise à jour de SYP" , - "could not write in directory" + "Thumbnails successfully created." => - "Impossible d'écrire dans le répertoire" + "Miniatures crées avec succès." , - "SYP is installed. You can now go to admin area" + "Error when creating thumbnails." => - "SYP est installé. Vous pouvez maintenant vous rendre dans la partie administration." + "Erreur lors de la création des miniatures." + , + + "SYP upgrade went smoothly. You can now go to admin area" + => + "La mise à jour de SYP s'est déroulée avec succès. Vous pouvez maintenant vous rendre dans la partie administration." , "SYP needs javascript. Please activate scripts in your browser." @@ -297,4 +322,4 @@ , ) -?> +?> \ No newline at end of file diff --git a/inc/i10n/updatelang.php b/inc/i10n/updatelang.php index 0d1498f..023797f 100755 --- a/inc/i10n/updatelang.php +++ b/inc/i10n/updatelang.php @@ -10,7 +10,7 @@ if (!(isset ($argc)) || !(isset ($argv))) { $ROOTDIR = "../../"; // scripts in rootdir we need to link to -$SCRIPTS = array ("admin", "index", "wizard"); +$SCRIPTS = array ("admin", "index", "upgrade", "wizard"); function usage() { global $argv; diff --git a/inc/settings.php b/inc/settings.php index 3f3a358..50797f0 100644 --- a/inc/settings.php +++ b/inc/settings.php @@ -21,6 +21,10 @@ define ("DBPREFIX", "syp_"); // to be writeable by SYP. define ("UPLOADDIR", "upload"); +// directory where generated thumbnails are stored. That directory needs to be +// writeable by SYP. +define ("THUMBSDIR", "upload/_thumbs"); + // title of your website define ("SITETITLE", "SYP"); @@ -32,4 +36,14 @@ define ("WEBMASTERMAIL", ""); // different between syp admin and images directory. Or if protocol is // different (for example, if syp admin is https and images directory is http) define ("IMGSDIRURL", ""); + +// url of tumbnails directory. If empty, syp will try to guess it from syp +// location and THUMBSDIR. So, you need to set that variable if host is +// different between syp admin and images directory. Or if protocol is +// different (for example, if syp admin is https and images directory is http) +define ("THUMBSDIRURL", ""); + +// max size (either width or height) of thumbnails. If one dimension of +// uploaded image is bigger, images will be resized. +define ("THUMBSMAXSIZE", 400); ?> diff --git a/inc/templates_index.php b/inc/templates_index.php index 7fd2bb4..3b70e7c 100644 --- a/inc/templates_index.php +++ b/inc/templates_index.php @@ -11,6 +11,11 @@ try { } $bbox = $connection->mbr (); +if (defined ("THUMBSMAXSIZE") && (THUMBSMAXSIZE > 0)) { + $thumbsmaxsize = THUMBSMAXSIZE; +} else { + $thumbsmaxsize = 400; // default value; +} ?> @@ -19,6 +24,21 @@ $bbox = $connection->mbr (); +