From e53fae8f70619eb859c14725221fd9c67954a8b8 Mon Sep 17 00:00:00 2001 From: Regis Houssin <regis@dolibarr.fr> Date: Mon, 30 Jul 2007 14:22:05 +0000 Subject: [PATCH] =?UTF-8?q?Fix:=20coh=E9rence=20sur=20l'affichage=20des=20?= =?UTF-8?q?images=20par=20rapport=20=E0=20leur=20taille?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/langs/en_US/products.lang | 2 +- htdocs/langs/fr_FR/products.lang | 2 +- htdocs/lib/functions.inc.php | 14 ++++++++++---- htdocs/product.class.php | 15 +++++++++++++++ htdocs/product/photos.php | 17 +++++++++++++---- 5 files changed, 40 insertions(+), 10 deletions(-) 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 '<img border="0" height="120" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&file='.urlencode($pdir.$filename).'">'; + print '<img border="0" width="'.$imgWidth.'" height="'.$imgHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&file='.urlencode($pdir.$filename).'">'; print '</a>'; print '<br>'.$langs->trans("File").': '.dolibarr_trunc($viewfilename,16); print '<br>'; - // 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 '<a href="'.$_SERVER["PHP_SELF"].'?id='.$_GET["id"].'&action=addthumb&file='.urlencode($pdir.$viewfilename).'">'.img_refresh($langs->trans('RegenerateThumb')).' </a>'; + print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$_GET["id"].'&action=addthumb&file='.urlencode($pdir.$viewfilename).'">'.img_refresh($langs->trans('GenerateThumb')).' </a>'; } if ($user->rights->produit->creer) { -- GitLab