Browse Source

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/*
pull/6/head
brunoduc 2 years ago committed by GitHub
parent
commit
4bb8d187da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 62
      module/gallery/gallery.php
  2. 9
      module/gallery/view/gallery/gallery.php

62
module/gallery/gallery.php

@ -41,7 +41,37 @@ class gallery extends common {
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() {
// Traitement du tri
@ -303,11 +333,41 @@ class gallery extends common {
// La galerie existe
else {
// 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']);
if(is_dir($directory)) {
$iterator = new DirectoryIterator($directory);
foreach($iterator as $fileInfos) {
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())]);
}
}
@ -398,4 +458,4 @@ class galleriesHelper extends helper {
}
return $dirContent;
}
}
}

9
module/gallery/view/gallery/gallery.php

@ -13,12 +13,15 @@
<?php foreach($module::$pictures as $picture => $legend): ?>
<?php if($i % 4 === 1): ?>
<div class="row">
<?php endif; ?>
<?php
endif;
$thumb_url = str_replace("source", "thumb", helper::baseUrl(false) . $picture);
?>
<div class="col3">
<a
href="<?php echo helper::baseUrl(false) . $picture; ?>"
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; ?>"
>
<?php if($legend): ?>
@ -30,4 +33,4 @@
</div>
<?php endif; ?>
<?php $i++; ?>
<?php endforeach; ?>
<?php endforeach; ?>

Loading…
Cancel
Save