Création d'images miniatures (#1)

* Création d'images miniatures

En cas d'ajout de photos dans /site/file/source/* directement sans passer par le filemanager.

* Utilise les miniatures de /site/file/thumb/*
This commit is contained in:
brunoduc 2020-04-05 19:05:25 +02:00 committed by GitHub
parent 6330400c63
commit 4bb8d187da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 67 additions and 4 deletions

View File

@ -41,7 +41,37 @@ class gallery extends common {
const GALLERY_VERSION = '2.0'; const GALLERY_VERSION = '2.0';
// ************* Mofifié par @bruno **************
// **************** le 04/02/2020 ****************
private $width_thumb = 300; // Largeur des miniatures crées. hauteur respectant le ratio de image originale
public function IsDir_or_CreateIt($path) {
if (is_dir($path)) {
return true;
} else {
if (mkdir($path)) { return true; }
else { return false; }
}
}
public function CopyDir($origine, $destination) {
$test = scandir($origine);
foreach($test as $val) {
if($val!="." && $val!="..") {
if(is_dir($origine."/".$val)) {
CopyDir($origine."/".$val, $destination."/".$val);
IsDir_or_CreateIt($destination."/".$val);
}
}
}
return true;
}
public function fix_strtolower($str){
if (function_exists( 'mb_strtoupper' )) { return mb_strtolower($str); }
else { return strtolower($str); }
}
// ***********************************************
public function filter() { public function filter() {
// Traitement du tri // Traitement du tri
@ -303,11 +333,41 @@ class gallery extends common {
// La galerie existe // La galerie existe
else { else {
// Images de la galerie // Images de la galerie
$need_dir = true; // Si besion de créer des miniatures, recrée si besion l'arborescence du/des répertoires.
$directory = $this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'config', 'directory']); $directory = $this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'config', 'directory']);
if(is_dir($directory)) { if(is_dir($directory)) {
$iterator = new DirectoryIterator($directory); $iterator = new DirectoryIterator($directory);
foreach($iterator as $fileInfos) { foreach($iterator as $fileInfos) {
if($fileInfos->isDot() === false AND $fileInfos->isFile() AND @getimagesize($fileInfos->getPathname())) { if($fileInfos->isDot() === false AND $fileInfos->isFile() AND @getimagesize($fileInfos->getPathname())) {
$rp = realpath($fileInfos->getPathname());
$tp = str_replace("source", "thumb", $rp);
if (is_readable($tp)) {
$info = pathinfo($tp);
if (in_array(strtolower($info['extension']), array( 'jpg', 'jpeg', 'png' ))) {
$gis = getimagesize("$tp");
if ($gis[0]<$this->width_thumb) { $need_resize = true; }
else { $need_resize = false; }
}
}
else { $need_resize = true; }
if ($need_resize) {
if ($need_dir) {
$dir = dirname($tp);
$p = explode ( "thumb" , $dir);
if (!is_dir($dir)) { // Création de TOUT les dossiers et sous dossiers
$p = explode ( "thumb" , $dir);
CopyDir("$p[0]source", "$p[0]thumb");
$need_dir = false;
}
}
$_SESSION['RF']["verify"] = "RESPONSIVEfilemanager"; // Pour éviter un forbiden dans la face
@require_once("core/vendor/filemanager/include/utils.php"); // Désolé pour @, pour éviter les erreurs
require_once("core/vendor/filemanager/include/php_image_magician.php");
$magicianObj = new imageLib($rp);
$magicianObj -> resizeImage($this->width_thumb, 300, 2);
$magicianObj -> saveImage($tp);
}
self::$pictures[$directory . '/' . $fileInfos->getFilename()] = $this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'legend', str_replace('.','',$fileInfos->getFilename())]); self::$pictures[$directory . '/' . $fileInfos->getFilename()] = $this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'legend', str_replace('.','',$fileInfos->getFilename())]);
} }
} }

View File

@ -13,12 +13,15 @@
<?php foreach($module::$pictures as $picture => $legend): ?> <?php foreach($module::$pictures as $picture => $legend): ?>
<?php if($i % 4 === 1): ?> <?php if($i % 4 === 1): ?>
<div class="row"> <div class="row">
<?php endif; ?> <?php
endif;
$thumb_url = str_replace("source", "thumb", helper::baseUrl(false) . $picture);
?>
<div class="col3"> <div class="col3">
<a <a
href="<?php echo helper::baseUrl(false) . $picture; ?>" href="<?php echo helper::baseUrl(false) . $picture; ?>"
class="galleryGalleryPicture" class="galleryGalleryPicture"
style="background-image:url('<?php echo helper::baseUrl(false) . $picture; ?>')" style="background-image:url('<?php echo $thumb_url; ?>')"
data-caption="<?php echo $legend; ?>" data-caption="<?php echo $legend; ?>"
> >
<?php if($legend): ?> <?php if($legend): ?>