Fix: cohrence sur l'affichage des images par rapport leur taille

This commit is contained in:
Regis Houssin
2007-07-30 14:22:05 +00:00
parent fb966b5503
commit e53fae8f70
5 changed files with 40 additions and 10 deletions

View File

@@ -117,4 +117,4 @@ PriceQtyTTC=Price for this quantity TTC
NoPriceDefinedForThisSupplier=No price/qty defined for this supplier/product NoPriceDefinedForThisSupplier=No price/qty defined for this supplier/product
RecordedProducts=Products recorded RecordedProducts=Products recorded
RecordedProductsAndServices=Products/services recorded RecordedProductsAndServices=Products/services recorded
RegenerateThumb=Regenerate thumb GenerateThumb=Generate thumb

View File

@@ -117,4 +117,4 @@ PriceQtyTTC=Prix pour la quantit
NoPriceDefinedForThisSupplier=Aucun prix/qt<71> d<>fini pour ce fournisseur/produit NoPriceDefinedForThisSupplier=Aucun prix/qt<71> d<>fini pour ce fournisseur/produit
RecordedProducts=Produits en vente RecordedProducts=Produits en vente
RecordedProductsAndServices=Produits/services en vente RecordedProductsAndServices=Produits/services en vente
RegenerateThumb=R<EFBFBD>g<EFBFBD>n<EFBFBD>rer la vignette GenerateThumb=G<EFBFBD>n<EFBFBD>rer la vignette

View File

@@ -2948,14 +2948,14 @@ function print_date_range($date_start,$date_end)
* \return imgThumbName Chemin de la vignette * \return imgThumbName Chemin de la vignette
*/ */
function vignette($file, $maxWidth = 160, $maxHeight = 120){ function vignette($file, $maxWidth = 160, $maxHeight = 120){
// V<>rification des erreurs dans les param<61>tres de la fonction // V<>rification des erreurs dans les param<61>tres de la fonction
//============================================================ //============================================================
if(!file_exists($file)){ if(!file_exists($file)){
// Si le fichier pass<73> en param<61>tre n'existe pas // Si le fichier pass<73> en param<61>tre n'existe pas
return 'Le fichier '.$file.' n\'a pas <20>t<EFBFBD> trouv<75> sur le serveur.'; return 'Le fichier '.$file.' n\'a pas <20>t<EFBFBD> trouv<75> sur le serveur.';
} }
elseif(!eregi('(\.jpg|\.png)$',$files['name'])) elseif(!eregi('(\.jpg|\.png)$',$file))
{ {
// Todo: Ajouter cr<63>ation vignette pour les autres formats d'images // Todo: Ajouter cr<63>ation vignette pour les autres formats d'images
return 'Le fichier '.$file.' n\'ai pas g<>r<EFBFBD> pour le moment.'; return 'Le fichier '.$file.' n\'ai pas g<>r<EFBFBD> pour le moment.';
@@ -2973,14 +2973,20 @@ function vignette($file, $maxWidth = 160, $maxHeight = 120){
return 'Valeur de la hauteur incorrecte.'; return 'Valeur de la hauteur incorrecte.';
} }
//============================================================ //============================================================
$fichier = realpath($file); // Chemin canonique absolu de l'image $fichier = realpath($file); // Chemin canonique absolu de l'image
$dir = dirname($file).'/'; // Chemin du dossier contenant l'image $dir = dirname($file).'/'; // Chemin du dossier contenant l'image
$dirthumb = $dir.'thumbs/'; // Chemin du dossier contenant les vignettes $dirthumb = $dir.'thumbs/'; // Chemin du dossier contenant les vignettes
$infoImg = getimagesize($fichier); // R<>cup<75>ration des infos de l'image $infoImg = getimagesize($fichier); // R<>cup<75>ration des infos de l'image
$imgWidth = $infoImg[0]; // Largeur de l'image $imgWidth = $infoImg[0]; // Largeur de l'image
$imgHeight = $infoImg[1]; // Hauteur 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<63>e pas de vignette
if ($infoImg[0] < $maxWidth && $infoImg[1] < $maxHeight)
{
return 'Le fichier '.$file.' ne n<>cessite pas de cr<63>ation de vignette';
}
// On cr<63>e le r<>pertoire contenant les vignettes // On cr<63>e le r<>pertoire contenant les vignettes
if (! file_exists($dirthumb)) if (! file_exists($dirthumb))
{ {

View File

@@ -79,6 +79,10 @@ class Product
var $stats_contrat=array(); var $stats_contrat=array();
var $stats_facture=array(); var $stats_facture=array();
var $multilangs=array(); var $multilangs=array();
//! Taille de l'image
var $imgWidth;
var $imgHeight;
//! Intitule de l'erreur //! Intitule de l'erreur
var $error; var $error;
@@ -2382,6 +2386,17 @@ class Product
} }
} }
} }
/**
* \brief R<>cup<75>re la taille de l'image
* \param file Chemin de l'image
*/
function get_image_size($file)
{
$infoImg = getimagesize($file); // R<>cup<75>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 * \brief Charge indicateurs this->nb de tableau de bord

View File

@@ -167,6 +167,9 @@ if ($_GET["id"] || $_GET["ref"])
$nbphoto=0; $nbphoto=0;
$nbbyrow=5; $nbbyrow=5;
$maxWidth = 160;
$maxHeight = 120;
$pdir = get_exdir($product->id,2) . $product->id ."/photos/"; $pdir = get_exdir($product->id,2) . $product->id ."/photos/";
$dir = $conf->produit->dir_output . '/'. $pdir; $dir = $conf->produit->dir_output . '/'. $pdir;
@@ -196,16 +199,22 @@ if ($_GET["id"] || $_GET["ref"])
// Nom affich<63> // Nom affich<63>
$viewfilename=$obj['photo']; $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 '</a>';
print '<br>'.$langs->trans("File").': '.dolibarr_trunc($viewfilename,16); print '<br>'.$langs->trans("File").': '.dolibarr_trunc($viewfilename,16);
print '<br>'; print '<br>';
// On propose la g<>n<EFBFBD>ration de la vignette si elle n'existe pas
if (!$obj['photo_vignette'] && eregi('(\.jpg|\.png)$',$obj['photo'])) // On propose la g<>n<EFBFBD>ration de la vignette si elle n'existe pas et si la taille est sup<75>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"].'&amp;action=addthumb&amp;file='.urlencode($pdir.$viewfilename).'">'.img_refresh($langs->trans('RegenerateThumb')).'&nbsp;&nbsp;</a>'; print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$_GET["id"].'&amp;action=addthumb&amp;file='.urlencode($pdir.$viewfilename).'">'.img_refresh($langs->trans('GenerateThumb')).'&nbsp;&nbsp;</a>';
} }
if ($user->rights->produit->creer) if ($user->rights->produit->creer)
{ {