[10.0.053] Création des miniatures pour les galeries existantes WIP

This commit is contained in:
Fred Tempez 2020-04-06 09:41:02 +02:00
parent bf9ba87c37
commit 543c4911da
2 changed files with 67 additions and 8 deletions

View File

@ -32,8 +32,11 @@ class common {
const FILE_DIR = 'site/file/'; const FILE_DIR = 'site/file/';
const TEMP_DIR = 'site/tmp/'; const TEMP_DIR = 'site/tmp/';
// Miniatures de la gallery
const THUMBS_SEPARATOR = 'mini_';
// Numéro de version // Numéro de version
const ZWII_VERSION = '10.0.052'; const ZWII_VERSION = '10.0.053';
const ZWII_UPDATE_CHANNEL = "v10"; const ZWII_UPDATE_CHANNEL = "v10";
public static $actions = []; public static $actions = [];
@ -781,9 +784,51 @@ class common {
} }
/*
* Création d'une miniature
* Fonction utilisée lors de la mise à jour d'une version 9 à une version 10
* @param string $src image source
* @param string $dets image destination
* @param integer $desired_width largeur demandée
*/
function makeThumb($src, $dest, $desired_width) {
$png = $jpg = false;
if (strpos($src,'jpg') > 0 ||
strpos($src,'jpeg') > 0 ) {
$jpg = true;
}
if (strpos($src,'png') > 0 ) {
$png = true;
}
if ($png || $jpg ) {
/* read the source image */
$source_image = $jpg ? imagecreatefromjpeg($src) : imagecreatefrompng($src);
$width = imagesx($source_image);
$height = imagesy($source_image);
/* find the "desired height" of this thumbnail, relative to the desired width */
$desired_height = floor($height * ($desired_width / $width));
/* create a new, "virtual" image */
$virtual_image = imagecreatetruecolor($desired_width, $desired_height);
/* copy source image at a resized size */
imagecopyresampled($virtual_image, $source_image, 0, 0, 0, 0, $desired_width, $desired_height, $width, $height);
/* create the physical thumbnail image to its destination */
if ($png) {
imagepng($virtual_image, $dest);
}
if ($jpg) {
imagejpeg($virtual_image, $dest);
}
}
}
/** /**
* Envoi un mail * Envoi un mail
* @param string|array $to Destinataire * @param string|array $to Destinataire
* @param string $subject Sujet * @param string $subject Sujet
@ -1116,7 +1161,9 @@ class common {
// Version 10.0.00 // Version 10.0.00
if($this->getData(['core', 'dataVersion']) < 10000) { if($this->getData(['core', 'dataVersion']) < 10000) {
$this->setData(['config', 'faviconDark','faviconDark.ico']); $this->setData(['config', 'faviconDark','faviconDark.ico']);
// Numérotation des galeries
//----------------------------------------
// Mettre à jour les données des galeries
$pageList = array(); $pageList = array();
foreach ($this->getHierarchy(null,null,null) as $parentKey=>$parentValue) { foreach ($this->getHierarchy(null,null,null) as $parentKey=>$parentValue) {
$pageList [] = $parentKey; $pageList [] = $parentKey;
@ -1142,18 +1189,32 @@ class common {
if ( $this->getdata(['module',$parent,$galleryKey,'config','homePicture']) === NULL) { if ( $this->getdata(['module',$parent,$galleryKey,'config','homePicture']) === NULL) {
$iterator = new DirectoryIterator($this->getdata(['module',$parent,$galleryKey,'config','directory'])); $iterator = new DirectoryIterator($this->getdata(['module',$parent,$galleryKey,'config','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())) {
$this->setdata(['module',$parent,$galleryKey,'config','homePicture',$fileInfos->getFilename()]); $this->setdata(['module',$parent,$galleryKey,'config','homePicture',$fileInfos->getFilename()]);
break; break;
} }
} }
} }
// Mise à jour de la taille des miniatures
$iterator = new DirectoryIterator($this->getdata(['module',$parent,$galleryKey,'config','directory']));
foreach($iterator as $fileInfos) {
if($fileInfos->isDot() === false AND $fileInfos->isFile() AND @getimagesize($fileInfos->getPathname())) {
if (!file_exists( str_replace('source','thumb',$fileInfos->getPathname()) . '/' . self::THUMBS_SEPARATOR . strtolower($fileInfos->getFilename()))) {
$this->makeThumb($fileInfos->getPathname(),
str_replace('source','thumb',$fileInfos->getPath()) . '/' . self::THUMBS_SEPARATOR . strtolower($fileInfos->getFilename()),
640);
}
}
}
} }
} }
} }
$this->setData(['core', 'dataVersion', 10000]); // Mettre à jour les données des galeries
} //----------------------------------------
$this->setData(['core', 'dataVersion', 10000]);
}
} }
} }

View File

@ -41,8 +41,6 @@ class gallery extends common {
public static $thumbs = []; public static $thumbs = [];
const THUMBS_SEPARATOR = 'mini_';
const GALLERY_VERSION = '2.0'; const GALLERY_VERSION = '2.0';