From 6867398ecffd78630481903b650faeb4b780c9cb Mon Sep 17 00:00:00 2001
From: Cerdic <cedric@yterium.com>
Date: Tue, 9 Feb 2021 12:25:48 +0100
Subject: [PATCH] Ajout de la possibilite de definir une largeur/hauteur mini
 pour les logo et ou les images (fix https://git.spip.net/spip/medias/pulls/9
 et #2378)

---
 inc/verifier_taille_document_acceptable.php | 38 +++++++++++++++++++--
 lang/medias_fr.php                          |  1 +
 2 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/inc/verifier_taille_document_acceptable.php b/inc/verifier_taille_document_acceptable.php
index d0406c90..884883e4 100644
--- a/inc/verifier_taille_document_acceptable.php
+++ b/inc/verifier_taille_document_acceptable.php
@@ -41,13 +41,17 @@ function inc_verifier_taille_document_acceptable_dist(&$infos, $is_logo = false)
 		if ($is_logo) {
 			$max_width = (defined('_LOGO_MAX_WIDTH') and _LOGO_MAX_WIDTH) ? _LOGO_MAX_WIDTH : null;
 			$max_height = (defined('_LOGO_MAX_HEIGHT') and _LOGO_MAX_HEIGHT) ? _LOGO_MAX_HEIGHT : null;
+			$min_width = (defined('_LOGO_MIN_WIDTH') and _LOGO_MIN_WIDTH) ? _LOGO_MIN_WIDTH : null;
+			$min_height = (defined('_LOGO_MIN_HEIGHT') and _LOGO_MIN_HEIGHT) ? _LOGO_MIN_HEIGHT : null;
 		}
 		else {
 			$max_width = (defined('_IMG_MAX_WIDTH') and _IMG_MAX_WIDTH) ? _IMG_MAX_WIDTH : null;
 			$max_height = (defined('_IMG_MAX_HEIGHT') and _IMG_MAX_HEIGHT) ? _IMG_MAX_HEIGHT : null;
+			$min_width = (defined('_IMG_MIN_WIDTH') and _IMG_MIN_WIDTH) ? _IMG_MIN_WIDTH : null;
+			$min_height = (defined('_IMG_MIN_HEIGHT') and _IMG_MIN_HEIGHT) ? _IMG_MIN_HEIGHT : null;
 		}
 
-		$res = medias_verifier_largeur_hauteur_image($infos, $max_width, $max_height);
+		$res = medias_verifier_largeur_hauteur_image($infos, $max_width, $max_height, $min_width, $min_height);
 		if ($res !== true) {
 			return $res;
 		}
@@ -70,12 +74,15 @@ function inc_verifier_taille_document_acceptable_dist(&$infos, $is_logo = false)
 
 /**
  * Verifier largeur maxi et hauteur maxi d'une image
+ * + largeur mini et hauteur mini
  * @param array $infos
  * @param null|int $max_width
  * @param null|int $max_height
+ * @param null|int $min_width
+ * @param null|int $min_height
  * @return bool|string
  */
-function medias_verifier_largeur_hauteur_image($infos, $max_width = null, $max_height = null) {
+function medias_verifier_largeur_hauteur_image($infos, $max_width = null, $max_height = null, $min_width = null, $min_height = null) {
 
 	if (($max_width and $infos['largeur'] > $max_width)
 		or ($max_height and $infos['hauteur'] > $max_height)
@@ -124,6 +131,33 @@ function medias_verifier_largeur_hauteur_image($infos, $max_width = null, $max_h
 		}
 	}
 
+	if (($min_width and $infos['largeur'] < $min_width)
+		or ($min_height and $infos['hauteur'] < $min_height)
+	) {
+		return _T(
+			'medias:info_image_min_taille',
+			array(
+				'maxi' =>
+					_T(
+						'info_largeur_vignette',
+						array(
+							'largeur_vignette' => $min_width,
+							'hauteur_vignette' => $min_height
+						)
+					),
+				'actuel' =>
+					_T(
+						'info_largeur_vignette',
+						array(
+							'largeur_vignette' => $infos['largeur'],
+							'hauteur_vignette' => $infos['hauteur']
+						)
+					)
+			)
+		);
+	}
+
+
 	return true;
 }
 
diff --git a/lang/medias_fr.php b/lang/medias_fr.php
index 1e2154b6..43f64b51 100644
--- a/lang/medias_fr.php
+++ b/lang/medias_fr.php
@@ -115,6 +115,7 @@ $GLOBALS[$GLOBALS['idx_lang']] = array(
 	'info_illustrations' => 'Illustrations',
 	'info_image_max_poids' => 'Les images doivent obligatoirement faire moins de @maxi@ (ce fichier fait @actuel@).',
 	'info_image_max_taille' => 'Les images doivent obligatoirement faire moins de @maxi@ (ce fichier fait @actuel@).',
+	'info_image_min_taille' => 'Les images doivent obligatoirement faire au moins @mini@ (ce fichier fait @actuel@).',
 	'info_inclusion_directe' => 'Inclusion directeƂ :',
 	'info_inclusion_vignette' => 'Inclusion de la vignetteƂ :',
 	'info_installer_tous_documents' => 'Installer tous les documents',
-- 
GitLab