Version 4.3.2

This commit is contained in:
LC 2023-10-30 11:14:59 +01:00
parent 0399cb07fb
commit ed74256a6f
1 changed files with 58 additions and 51 deletions

View File

@ -5,7 +5,7 @@
*/ */
setlocale(LC_NUMERIC,'English','en_US','en_US.UTF-8'); setlocale(LC_NUMERIC,'English','en_US','en_US.UTF-8');
class album extends common { class album extends common {
const VERSION = '4.0'; const VERSION = '4.3.2';
const REALNAME = 'Album Photo'; const REALNAME = 'Album Photo';
const DELETE = true; const DELETE = true;
const UPDATE = '0.0'; const UPDATE = '0.0';
@ -15,15 +15,10 @@ class album extends common {
const SORT_HAND = 'SORT_HAND'; const SORT_HAND = 'SORT_HAND';
public static $directories = []; public static $directories = [];
public static $firstPictures = []; public static $firstPictures = [];
public static $galleries = []; public static $galleries = [];
public static $galleriesId = []; public static $galleriesId = [];
public static $pictures = []; public static $pictures = [];
public static $picturesId = []; public static $picturesId = [];
public static $actions = [ public static $actions = [
@ -529,6 +524,7 @@ class albumHelper extends helper {
else { return false; } else { return false; }
} }
} }
// relevés exif gps des photos // relevés exif gps des photos
public static function gps_exif($foto) { public static function gps_exif($foto) {
if (!preg_match('/(\.jpe?g)$/i', $foto)) { if (!preg_match('/(\.jpe?g)$/i', $foto)) {
@ -572,26 +568,43 @@ class albumHelper extends helper {
$sign = ($hemisphere == 'W' || $hemisphere == 'S') ? -1 : 1; $sign = ($hemisphere == 'W' || $hemisphere == 'S') ? -1 : 1;
return $sign * ($degrees + $minutes/60 + $seconds/3600); return $sign * ($degrees + $minutes/60 + $seconds/3600);
} }
// formatage light des noms d'images // formatage light des noms d'images
public static function formate($foto) { public static function formate($foto) {
$foto = trim($foto); $foto = trim($foto);
$foto = preg_replace('/[^[:alnum:]_.\-\/]/', '', $foto); $foto = preg_replace('/[^[:alnum:]_.\-\/]/', '', $foto);
return $foto; return $foto;
} }
// reorientation
// renommage des fichiers transformés
public static function renamePic($foto) {
$imor = basename($foto);
$extension = strrchr($imor,'.');
$namimor = str_replace($extension,'',$imor);
$redimg = dirname($foto).'/'.$namimor.'_t960.jpg';
return $redimg;
}
// backup des images réorientées ou redimensionnées
public static function backUp($foto) {
$backup = dirname($foto).'/backup';
self::makeDir($backup);
$backimg = $backup.'/'.strtolower(str_replace('.jpeg','.jpg',basename($foto)));
rename($foto,$backimg);
}
// réorientation
public static function reorientation($foto) { public static function reorientation($foto) {
$size = @getimagesize($foto); $size = @getimagesize($foto);
$mime = $size['mime']; $mime = $size['mime'];
if ((function_exists('exif_read_data')) && ($mime == 'image/jpeg')) // seules les images/jpeg sont réorientées
{ if ((function_exists('exif_read_data')) && ($mime == 'image/jpeg')) {
$exif = @exif_read_data($foto); $exif = @exif_read_data($foto);
$image = imagecreatefromstring(file_get_contents($foto)); $image = imagecreatefromstring(file_get_contents($foto));
if ($image !== false) { if ($image !== false) {
$orientation = isset($exif['Orientation']) === true ? $exif['Orientation'] : ''; $orientation = isset($exif['Orientation']) === true ? $exif['Orientation'] : '';
if ( (!empty($orientation)) && ($orientation != 1) ) if ( (!empty($orientation)) && ($orientation != 1) ) {
{ switch($orientation) {
switch($orientation)
{
case 3: case 3:
$image = imagerotate($image,180,0); $image = imagerotate($image,180,0);
break; break;
@ -602,28 +615,24 @@ class albumHelper extends helper {
$image = imagerotate($image,90,0); $image = imagerotate($image,90,0);
break; break;
} }
imagejpeg($image, $foto, 90); imagejpeg($image, self::renamePic($foto), 80);
} self::backUp($foto);
echo '<script>document.location.reload(false);</script>';
exit('Réorientation des photos...');
}
} }
} }
} }
// redimension // redimension
public static function redimension($foto) { public static function redimension($foto) {
$max_size = 960;// ex1280 dimension du plus petit côté $max_size = 960;// dimension du plus petit côté
$infoto = @getimagesize($foto); $infoto = @getimagesize($foto);
$large = $infoto[0]; $large = $infoto[0];
$haut = $infoto[1]; $haut = $infoto[1];
$type = $infoto[2]; $type = $infoto[2];
// seules les images/jpeg sont redimensionnées // seules les images/jpeg sont redimensionnées
if (($type == 2) && ($large > $max_size) && ($haut > $max_size)) { if (($type == 2) && ($large > $max_size) && ($haut > $max_size)) {
$imar = substr(strrchr($foto, '/'), 1);
$urlimar = str_replace($imar,'',$foto);
$backup = $urlimar.'backup';
self::makeDir($backup);
$extension = strrchr($imar,'.');
$namimar = str_replace($extension,'',$imar);
$redimg = $urlimar.$namimar.'_t960.jpg';
$backimg = $backup.'/'.strtolower(str_replace('.jpeg','.jpg',$imar));
$src = imagecreatefromjpeg($foto); $src = imagecreatefromjpeg($foto);
imageinterlace($src, true); imageinterlace($src, true);
if ($large > $haut) { if ($large > $haut) {
@ -633,18 +642,23 @@ class albumHelper extends helper {
$im = imagecreatetruecolor($max_size, round(($max_size/$large)*$haut)); $im = imagecreatetruecolor($max_size, round(($max_size/$large)*$haut));
imagecopyresampled($im, $src, 0, 0, 0, 0, $max_size, round($haut*($max_size/$large)), $large, $haut); imagecopyresampled($im, $src, 0, 0, 0, 0, $max_size, round($haut*($max_size/$large)), $large, $haut);
} }
imagejpeg($im, $redimg, 80); if (strpos($foto, 't960.') == false) {
imagedestroy($im); imagejpeg($im, self::renamePic($foto), 80);
rename($foto,$backimg); imagedestroy($im);
self::backUp($foto);
} else {
imagejpeg($im, $foto, 80);
imagedestroy($im);
}
echo '<script>document.location.reload(false);</script>'; echo '<script>document.location.reload(false);</script>';
exit(0); exit('Redimension des photos...');
} }
} }
// contrôle des photos // contrôle des photos
public static function controle($foto) { public static function controle($foto) {
$tn_tmp = substr(strrchr($foto, '/'), 1); $tn_tmp = basename($foto);
$url_picture = str_replace('/'.$tn_tmp,'',$foto); $minidos = substr(strrchr(dirname($foto), '/'), 1);
$minidos = substr(strrchr($url_picture, '/'), 1);
$mini = 'site/file/cache/'.$minidos.'/'.$tn_tmp; $mini = 'site/file/cache/'.$minidos.'/'.$tn_tmp;
if (!file_exists($mini)) { if (!file_exists($mini)) {
$valid = array('-', '_','.'); $valid = array('-', '_','.');
@ -652,7 +666,7 @@ class albumHelper extends helper {
$nommage = self::formate($foto); $nommage = self::formate($foto);
$foto = rename($foto,$nommage); $foto = rename($foto,$nommage);
echo '<script>document.location.reload(false);</script>'; echo '<script>document.location.reload(false);</script>';
exit(0); exit('Renommage des photos...');
} else { } else {
self::reorientation($foto); self::reorientation($foto);
self::redimension($foto); self::redimension($foto);
@ -661,6 +675,7 @@ class albumHelper extends helper {
return $foto; return $foto;
clearstatcache(); clearstatcache();
} }
// Thumbnailer // Thumbnailer
public static function makeThumbnail($foto) { public static function makeThumbnail($foto) {
if ( is_file($foto) && substr(mime_content_type($foto), 0, 5) == 'image' ) { if ( is_file($foto) && substr(mime_content_type($foto), 0, 5) == 'image' ) {
@ -671,9 +686,8 @@ class albumHelper extends helper {
$size_img = filesize($foto); $size_img = filesize($foto);
$dossiercache = 'site/file/cache'; $dossiercache = 'site/file/cache';
self::makeDir($dossiercache); self::makeDir($dossiercache);
$par = substr(strrchr($foto, '/'), 1); $par = basename($foto);
$url_par = str_replace('/'.$par,'',$foto); $cache = substr(strrchr(dirname($foto), '/'), 1);
$cache = substr(strrchr($url_par, '/'), 1);
self::makeDir($dossiercache.'/'.$cache); self::makeDir($dossiercache.'/'.$cache);
$extension = strrchr($par,'.'); $extension = strrchr($par,'.');
$vignette = str_replace($extension,'',$par); $vignette = str_replace($extension,'',$par);
@ -682,14 +696,12 @@ class albumHelper extends helper {
if (!file_exists($miniature)) { if (!file_exists($miniature)) {
list($width, $height, $type, $attr) = getimagesize($foto); list($width, $height, $type, $attr) = getimagesize($foto);
if ($height > $tnhaut) if ($height > $tnhaut) {
{
$convert = $tnhaut/$height; $convert = $tnhaut/$height;
$height = $tnhaut; $height = $tnhaut;
$width = ceil($width*$convert); $width = ceil($width*$convert);
} }
if ($width > $tnlarge) if ($width > $tnlarge) {
{
$convert = $tnlarge/$width; $convert = $tnlarge/$width;
$width = $tnlarge; $width = $tnlarge;
$height = ceil($height*$convert); $height = ceil($height*$convert);
@ -698,25 +710,21 @@ class albumHelper extends helper {
$largeur = $width; $largeur = $width;
$hauteur = $height; $hauteur = $height;
if($type == 1) if($type == 1) {
{
$img_in = imagecreatefromgif($foto); $img_in = imagecreatefromgif($foto);
} }
elseif($type == 2) elseif($type == 2) {
{
$img_in = imagecreatefromjpeg($foto); $img_in = imagecreatefromjpeg($foto);
} }
elseif($type == 3) elseif($type == 3) {
{
$img_in = imagecreatefrompng($foto); $img_in = imagecreatefrompng($foto);
} }
elseif($type == 18) elseif($type == 18) {
{
$img_in = imagecreatefromwebp($foto); $img_in = imagecreatefromwebp($foto);
} }
imageinterlace($img_in, true); imageinterlace($img_in, true);
$img_out = imagecreatetruecolor($largeur, $hauteur) or die ('Impossible de créer un flux d\'image GD'); $img_out = imagecreatetruecolor($largeur, $hauteur) or die ('Unable to create a GD image stream');
imagecopyresampled($img_out, $img_in, 0, 0, 0, 0, imagesx($img_out), imagesy($img_out), imagesx($img_in), imagesy($img_in)); 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); imagewebp($img_out, $miniature, 80);
@ -725,8 +733,7 @@ class albumHelper extends helper {
return $miniature; return $miniature;
clearstatcache(); clearstatcache();
} }
else {echo 'This is not an image';} else { die ('This is not an image'); }
} // makeThumbnail } // makeThumbnail
} // albumHelper } // albumHelper