diff --git a/htdocs/langs/en_US/products.lang b/htdocs/langs/en_US/products.lang index 205a2d2de4d..b2e434cf9d2 100644 --- a/htdocs/langs/en_US/products.lang +++ b/htdocs/langs/en_US/products.lang @@ -117,4 +117,4 @@ PriceQtyTTC=Price for this quantity TTC NoPriceDefinedForThisSupplier=No price/qty defined for this supplier/product RecordedProducts=Products recorded RecordedProductsAndServices=Products/services recorded -RegenerateThumb=Regenerate thumb \ No newline at end of file +GenerateThumb=Generate thumb \ No newline at end of file diff --git a/htdocs/langs/fr_FR/products.lang b/htdocs/langs/fr_FR/products.lang index 88b77e8099a..2f38baf8455 100644 --- a/htdocs/langs/fr_FR/products.lang +++ b/htdocs/langs/fr_FR/products.lang @@ -117,4 +117,4 @@ PriceQtyTTC=Prix pour la quantit NoPriceDefinedForThisSupplier=Aucun prix/qté défini pour ce fournisseur/produit RecordedProducts=Produits en vente RecordedProductsAndServices=Produits/services en vente -RegenerateThumb=Régénérer la vignette \ No newline at end of file +GenerateThumb=Générer la vignette \ No newline at end of file diff --git a/htdocs/lib/functions.inc.php b/htdocs/lib/functions.inc.php index 452fed9b8ac..28fd06c6b2a 100644 --- a/htdocs/lib/functions.inc.php +++ b/htdocs/lib/functions.inc.php @@ -2948,14 +2948,14 @@ function print_date_range($date_start,$date_end) * \return imgThumbName Chemin de la vignette */ function vignette($file, $maxWidth = 160, $maxHeight = 120){ - + // Vérification des erreurs dans les paramètres de la fonction //============================================================ if(!file_exists($file)){ // Si le fichier passé en paramètre n'existe pas return 'Le fichier '.$file.' n\'a pas été trouvé sur le serveur.'; } - elseif(!eregi('(\.jpg|\.png)$',$files['name'])) + elseif(!eregi('(\.jpg|\.png)$',$file)) { // Todo: Ajouter création vignette pour les autres formats d'images return 'Le fichier '.$file.' n\'ai pas géré pour le moment.'; @@ -2973,14 +2973,20 @@ function vignette($file, $maxWidth = 160, $maxHeight = 120){ return 'Valeur de la hauteur incorrecte.'; } //============================================================ - + $fichier = realpath($file); // Chemin canonique absolu de l'image $dir = dirname($file).'/'; // Chemin du dossier contenant l'image $dirthumb = $dir.'thumbs/'; // Chemin du dossier contenant les vignettes $infoImg = getimagesize($fichier); // Récupération des infos de l'image $imgWidth = $infoImg[0]; // Largeur de l'image $imgHeight = $infoImg[1]; // Hauteur de l'image - + + // Si l'image est plus petite que la largeur et le hauteur max, on ne crée pas de vignette + if ($infoImg[0] < $maxWidth && $infoImg[1] < $maxHeight) + { + return 'Le fichier '.$file.' ne nécessite pas de création de vignette'; + } + // On crée le répertoire contenant les vignettes if (! file_exists($dirthumb)) { diff --git a/htdocs/product.class.php b/htdocs/product.class.php index ed2444faeda..e957e2a0eb8 100644 --- a/htdocs/product.class.php +++ b/htdocs/product.class.php @@ -79,6 +79,10 @@ class Product var $stats_contrat=array(); var $stats_facture=array(); var $multilangs=array(); + + //! Taille de l'image + var $imgWidth; + var $imgHeight; //! Intitule de l'erreur var $error; @@ -2382,6 +2386,17 @@ class Product } } } + + /** + * \brief Récupère la taille de l'image + * \param file Chemin de l'image + */ + function get_image_size($file) + { + $infoImg = getimagesize($file); // Récupération des infos de l'image + $this->imgWidth = $infoImg[0]; // Largeur de l'image + $this->imgHeight = $infoImg[1]; // Hauteur de l'image + } /** * \brief Charge indicateurs this->nb de tableau de bord diff --git a/htdocs/product/photos.php b/htdocs/product/photos.php index 946e0428470..37f129f3171 100644 --- a/htdocs/product/photos.php +++ b/htdocs/product/photos.php @@ -167,6 +167,9 @@ if ($_GET["id"] || $_GET["ref"]) $nbphoto=0; $nbbyrow=5; + $maxWidth = 160; + $maxHeight = 120; + $pdir = get_exdir($product->id,2) . $product->id ."/photos/"; $dir = $conf->produit->dir_output . '/'. $pdir; @@ -196,16 +199,22 @@ if ($_GET["id"] || $_GET["ref"]) // Nom affiché $viewfilename=$obj['photo']; + + // Taille de l'image + $product->get_image_size($dir.$filename); + $imgWidth = ($product->imgWidth < $maxWidth) ? $product->imgWidth : $maxWidth; + $imgHeight = ($product->imgHeight < $maxHeight) ? $product->imgHeight : $maxHeight; - print ''; + print ''; print ''; print '
'.$langs->trans("File").': '.dolibarr_trunc($viewfilename,16); print '
'; - // On propose la génération de la vignette si elle n'existe pas - if (!$obj['photo_vignette'] && eregi('(\.jpg|\.png)$',$obj['photo'])) + + // On propose la génération de la vignette si elle n'existe pas et si la taille est supérieure aux limites + if (!$obj['photo_vignette'] && eregi('(\.jpg|\.png)$',$obj['photo']) && ($product->imgWidth > $maxWidth || $product->imgHeight > $maxHeight)) { - print ''.img_refresh($langs->trans('RegenerateThumb')).'  '; + print ''.img_refresh($langs->trans('GenerateThumb')).'  '; } if ($user->rights->produit->creer) {