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<71> d<>fini pour ce fournisseur/produit
RecordedProducts=Produits 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

@@ -2955,7 +2955,7 @@ function vignette($file, $maxWidth = 160, $maxHeight = 120){
// 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.';
}
elseif(!eregi('(\.jpg|\.png)$',$files['name']))
elseif(!eregi('(\.jpg|\.png)$',$file))
{
// 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.';
@@ -2981,6 +2981,12 @@ function vignette($file, $maxWidth = 160, $maxHeight = 120){
$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<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
if (! file_exists($dirthumb))
{

View File

@@ -80,6 +80,10 @@ class Product
var $stats_facture=array();
var $multilangs=array();
//! Taille de l'image
var $imgWidth;
var $imgHeight;
//! Intitule de l'erreur
var $error;
//! Numero de l'erreur
@@ -2383,6 +2387,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
* \return int <0 si ko, >0 si ok

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;
@@ -197,15 +200,21 @@ if ($_GET["id"] || $_GET["ref"])
// Nom affich<63>
$viewfilename=$obj['photo'];
print '<img border="0" height="120" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&file='.urlencode($pdir.$filename).'">';
// 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" 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<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)
{