Version 1.1

-réécriture de la fonction create_thumb: pour les images format portrait, les vignettes sont redimensionner à 300px de large, puis cropées à 300x200. Toutes les vignettes sont au format paysage.
-quelques corrections de bugs
This commit is contained in:
2025-02-13 17:38:01 +01:00
parent b35196fdb8
commit f0fa8b6efc
4 changed files with 81 additions and 14 deletions

View File

@@ -80,7 +80,7 @@
</form>
</div>
<p class="navPage"><a href="index.php" title="<?php echo gettext("Home"); ?>"><?php echo gettext("Home"); ?></a> | <a href="photo-du-mois.php" title="<?php echo gettext("Picture of the month"); ?>"><?php echo gettext("Picture of the month"); ?></a> | <a href="maps.php" title="<?php echo gettext("Maps"); ?>"><?php echo gettext("Maps"); ?></a> | <a href="admin.php" title="<?php echo gettext("Admin page"); ?>"><?php echo gettext("Admin page"); ?></a></p>
<p class="navPage"><a href="../index.php" title="<?php echo gettext("Home"); ?>"><?php echo gettext("Home"); ?></a> | <a href="../photo-du-mois.php" title="<?php echo gettext("Picture of the month"); ?>"><?php echo gettext("Picture of the month"); ?></a> | <a href="../maps.php" title="<?php echo gettext("Maps"); ?>"><?php echo gettext("Maps"); ?></a> | <a href="admin.php" title="<?php echo gettext("Admin page"); ?>"><?php echo gettext("Admin page"); ?></a></p>
<p><em><small>&copy; 2013-<?php echo date('Y'); ?> sur-le-sentier.fr</small></em></p>

View File

@@ -108,16 +108,11 @@ $i = 1;
$photos = array();
foreach($dir as $file){
/*
$file->getFilename()
pathName()
*/
$file = $file->getpathName();
//$file = $file->getFilename();
echo $file;
$x = in_bdd($file);
echo $x;
/*
if ($i > 5) {
break;
@@ -653,6 +648,9 @@ try {
$titre = $item['title']; // ***
$legende = $item['legende']; // ***
# Create Thumbnails (functions.php line 203)
$big = $chemin . $file;
create_thumb($th_w, $th_h, $big);

View File

@@ -201,12 +201,49 @@ function get_gps($exif) {
function create_thumb($thumb_w, $thumb_h, $image) {
global $chemin;
list($origin_w, $origin_h) = getimagesize($image);
$origin_ratio = round($origin_w / $origin_h, 1);
$outFile = str_replace("img", "thumb", $chemin) . basename($image);
$new_w = 300;
$new_h = 200;
//$f = $chemin . $image;
$thumb = new Imagick($image);
list($origin_w, $origin_h) = getimagesize($image);
$origin_ratio = round($origin_w / $origin_h, 1);
$outFile = str_replace("../photos/img", "../photos/thumb", $image);
if ($origin_w != null && $origin_h != null) {
if ($origin_w > $origin_h) {
$resize_w = $origin_w * $new_h / $origin_h;
$resize_h = $new_h;
//$thumb->resizeImage($resize_w, $resize_h, Imagick::FILTER_LANCZOS, 0.9);
$thumb->resizeImage($resize_w, $resize_h, Imagick::FILTER_CATROM, 0.9);
}
else {
if ($origin_w != null && $origin_h != null) {
$resize_w = $new_w;
$resize_h = $origin_h * $new_w / $origin_w; // 450
$thumb->resizeImage($resize_w, $resize_h, Imagick::FILTER_CATROM, 0.9); // 300 x 300
$thumb->cropImage($new_w, $new_h, ($resize_w - $new_w) / 2, ($resize_h - $new_h) / 2); // (w, h, x ,y) (xy coin haut gauche) (300, 200, 0, 125)
}
//$image->sharpenimage($radius, $sigma, $channel); // 5, 1
$thumb->sharpenimage(5, 1);
$thumb->setImageCompression(Imagick::COMPRESSION_ZIP);
// Set compression level (1 lowest quality, 100 highest quality)
$thumb->setImageCompressionQuality(75);
// Strip out unneeded meta data
$thumb->stripImage();
$thumb->writeImage($outFile);
$thumb->destroy();
/*
if ($thumb_w / $thumb_h > $origin_ratio) {
$thumb_w = $thumb_h * $origin_ratio;
} else {
@@ -219,8 +256,11 @@ if ($origin_w != null && $origin_h != null) {
$image->writeImage($outFile);
$image->destroy();
}
*/
}
}
}
/* Fonction in_bdd(): test si la photo est déjà dans la bdd
@@ -399,6 +439,11 @@ function data_for_lightbox($data) {
$latitude = $data['lat'];
$longitude = $data['long'];
$altitude = $data['alt'];
$width = $data['width'];
$height = $data['height'];
//echo $width . "-" . $height;
$gps = (!empty($longitude) && !empty($latitude)) ? $latitude . "," . $longitude : "";
//$gps = $longitude . "," . $latitude;
@@ -488,6 +533,8 @@ function data_for_lightbox($data) {
$lightbox['creator'] = $creator;
$lightbox['gps'] = $gps;
$lightbox['description'] = $description;
$lightbox['width'] = $width;
$lightbox['height'] = $height;
/*
Array

View File

@@ -56,6 +56,7 @@ else $page = intval($_GET['page']);
<?php
$chemin = 'photos/img/';
$chemin_thumb = str_replace("img", "thumb", $chemin);
$base = 'db_photo.sqlite3';
@@ -188,12 +189,33 @@ else exit("Database " . $base . " does not exist !");
} else {
$meta = '';
}
echo '<div class="item">';
echo '<a href ="' . $lb['big'] . '" title="' . htmlspecialchars($lb['title']) . '" data-lcl-txt="' . htmlspecialchars($lb['description']) . '" data-lcl-author="' . htmlspecialchars($lb['creator']) . '">';
/*
if ($lb['width'] > $lb['height']) {
echo '<img src="' . $lb['thumb'] . '" alt="' . htmlspecialchars($lb['title']) . '">';
}
else {
$f = $chemin . $result[$i]['filename'];
$image = new Imagick($f);
$new_w = 300;
$new_h = 200;
$resize_w = $new_w;
$resize_h = $lb['height'] * $new_w / $lb['width']; // 450
$image->resizeImage($resize_w, $resize_h, Imagick::FILTER_LANCZOS, 0.9); // 300 x 300
$image->cropImage($new_w, $new_h, ($resize_w - $new_w) / 2, ($resize_h - $new_h) / 2); // (w, h, x ,y) (xy coin haut gauche) (300, 200, 0, 125)
$thu = $chemin_thumb ."_" . $result[$i]['filename'];;
$image->writeImage($thu);
echo '<img src="' . $thu . '" alt="' . htmlspecialchars($lb['title']) . '">';
}
*/
echo '<img src="' . $lb['thumb'] . '" alt="' . htmlspecialchars($lb['title']) . '">';
echo "</a>";
echo '<span class="caption">' . month($date) . '</span>';