Version 4.0

This commit is contained in:
LC 2023-10-22 00:37:08 +02:00
parent c1cbadd1d5
commit 75079b6527
1 changed files with 71 additions and 3 deletions

View File

@ -362,7 +362,7 @@ class album extends common {
template::text('legend[' . $fileInfos->getFilename() . ']', [
'value' => $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'legend', str_replace('.','',$fileInfos->getFilename())])
]),
'<a href="'.$fileInfos->getPathname().'" rel="data-lity"><img class="config" src="module/album/plugins/thumbnailer.php?img='.$fileInfos->getPathname().'" alt="miniature"></a>'
'<a href="'.$fileInfos->getPathname().'" rel="data-lity"><img class="config" src="'.albumHelper::makeThumbnail($fileInfos->getPathname()).'" alt="miniature"></a>'
];
self::$picturesId [] = str_replace('.','',$fileInfos->getFilename());
}
@ -516,10 +516,11 @@ class album extends common {
}
}
/* ********************** albumHelper ********************** */
class albumHelper extends helper {
// dossier backup
// création des dossiers
public static function makeDir($rep) {
if (is_dir($rep)) {
return true;
@ -660,5 +661,72 @@ class albumHelper extends helper {
return $foto;
clearstatcache();
}
}
// Thumbnailer
public static function makeThumbnail($foto) {
if ( is_file($foto) && substr(mime_content_type($foto), 0, 5) == 'image' ) {
// taille des miniatures
$tnlarge = 320;
$tnhaut = ($tnlarge/1.6);
$size_img = filesize($foto);
$dossiercache = 'site/file/cache';
self::makeDir($dossiercache);
$par = substr(strrchr($foto, '/'), 1);
$url_par = str_replace('/'.$par,'',$foto);
$cache = substr(strrchr($url_par, '/'), 1);
self::makeDir($dossiercache.'/'.$cache);
$extension = strrchr($par,'.');
$vignette = str_replace($extension,'',$par);
$miniature = $dossiercache.'/'.$cache.'/tn-'.$vignette.'-'.$size_img.'.webp';
if (!file_exists($miniature)) {
list($width, $height, $type, $attr) = getimagesize($foto);
if ($height > $tnhaut)
{
$convert = $tnhaut/$height;
$height = $tnhaut;
$width = ceil($width*$convert);
}
if ($width > $tnlarge)
{
$convert = $tnlarge/$width;
$width = $tnlarge;
$height = ceil($height*$convert);
}
$largeur = $width;
$hauteur = $height;
if($type == 1)
{
$img_in = imagecreatefromgif($foto);
}
elseif($type == 2)
{
$img_in = imagecreatefromjpeg($foto);
}
elseif($type == 3)
{
$img_in = imagecreatefrompng($foto);
}
elseif($type == 18)
{
$img_in = imagecreatefromwebp($foto);
}
imageinterlace($img_in, true);
$img_out = imagecreatetruecolor($largeur, $hauteur) or die ('Impossible de créer un flux d\'image GD');
imagecopyresampled($img_out, $img_in, 0, 0, 0, 0, imagesx($img_out), imagesy($img_out), imagesx($img_in), imagesy($img_in));
imagewebp($img_out, $miniature, 80);
imagedestroy($img_out);
}
return $miniature;
clearstatcache();
}
else {echo 'This is not an image';}
} // makeThumbnail
} // albumHelper