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
RecordedProducts=Products 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é défini pour ce fournisseur/produit
RecordedProducts=Produits en vente
RecordedProductsAndServices=Produits/services en vente
RegenerateThumb=Régénérer la vignette
GenerateThumb=Générer la vignette

View File

@ -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))
{

View File

@ -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

View File

@ -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"].'&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)
{