Fix: Use correct constant

This commit is contained in:
Laurent Destailleur 2011-12-14 17:13:09 +01:00
parent f866c4590b
commit 1ffacf2d03

View File

@ -286,14 +286,15 @@ function dol_imageResizeOrCrop($file, $mode, $newWidth, $newHeight, $src_x=0, $s
/** /**
* Create a thumbnail from an image file (Supported extensions are gif, jpg, png and bmp). * Create a thumbnail from an image file (Supported extensions are gif, jpg, png and bmp).
* If file is myfile.jpg, new file may be myfile_small.jpg * If file is myfile.jpg, new file may be myfile_small.jpg
* @param file Path of source file to resize *
* @param maxWidth Largeur maximum que dois faire la miniature (-1=unchanged, 160 by default) * @param string $file Path of source file to resize
* @param maxHeight Hauteur maximum que dois faire l'image (-1=unchanged, 120 by default) * @param int $maxWidth Largeur maximum que dois faire la miniature (-1=unchanged, 160 by default)
* @param extName Extension to differenciate thumb file name ('_small', '_mini') * @param int $maxHeight Hauteur maximum que dois faire l'image (-1=unchanged, 120 by default)
* @param quality Quality of compression (0=worst, 100=best) * @param string $extName Extension to differenciate thumb file name ('_small', '_mini')
* @param outdir Directory where to store thumb * @param int $quality Quality of compression (0=worst, 100=best)
* @param targetformat New format of target (1,2,3,4 or 0 to keep old format) * @param string $outdir Directory where to store thumb
* @return string Full path of thumb * @param int $targetformat New format of target (1,2,3,... or 0 to keep old format)
* @return string Full path of thumb or '' if it fails
*/ */
function vignette($file, $maxWidth = 160, $maxHeight = 120, $extName='_small', $quality=50, $outdir='thumbs', $targetformat=0) function vignette($file, $maxWidth = 160, $maxHeight = 120, $extName='_small', $quality=50, $outdir='thumbs', $targetformat=0)
{ {
@ -355,16 +356,19 @@ function vignette($file, $maxWidth = 160, $maxHeight = 120, $extName='_small', $
$imgfonction=''; $imgfonction='';
switch($infoImg[2]) switch($infoImg[2])
{ {
case 1: // IMG_GIF case IMAGETYPE_GIF: // 1
$imgfonction = 'imagecreatefromgif'; $imgfonction = 'imagecreatefromgif';
break; break;
case 2: // IMG_JPG case IMAGETYPE_JPEG: // 2
$imgfonction = 'imagecreatefromjpeg'; $imgfonction = 'imagecreatefromjpeg';
break; break;
case 3: // IMG_PNG case IMAGETYPE_PNG: // 3
$imgfonction = 'imagecreatefrompng'; $imgfonction = 'imagecreatefrompng';
break; break;
case 4: // IMG_WBMP case IMAGETYPE_BMP: // 6
// Not supported by PHP GD
break;
case IMAGETYPE_WBMP: // 15
$imgfonction = 'imagecreatefromwbmp'; $imgfonction = 'imagecreatefromwbmp';
break; break;
} }
@ -384,23 +388,32 @@ function vignette($file, $maxWidth = 160, $maxHeight = 120, $extName='_small', $
// Initialisation des variables selon l'extension de l'image // Initialisation des variables selon l'extension de l'image
switch($infoImg[2]) switch($infoImg[2])
{ {
case 1: // Gif case IMAGETYPE_GIF: // 1
$img = imagecreatefromgif($fichier); $img = imagecreatefromgif($fichier);
$extImg = '.gif'; // Extension de l'image $extImg = '.gif'; // Extension de l'image
break; break;
case 2: // Jpg case IMAGETYPE_JPEG: // 2
$img = imagecreatefromjpeg($fichier); $img = imagecreatefromjpeg($fichier);
$extImg = '.jpg'; // Extension de l'image $extImg = '.jpg'; // Extension de l'image
break; break;
case 3: // Png case IMAGETYPE_PNG: // 3
$img = imagecreatefrompng($fichier); $img = imagecreatefrompng($fichier);
$extImg = '.png'; $extImg = '.png';
break; break;
case 4: // Bmp case IMAGETYPE_BMP: // 6
// Not supported by PHP GD
$extImg = '.bmp';
break;
case IMAGETYPE_WBMP: // 15
$img = imagecreatefromwbmp($fichier); $img = imagecreatefromwbmp($fichier);
$extImg = '.bmp'; $extImg = '.bmp';
break; break;
} }
if (! is_resource($img))
{
dol_syslog('Failed to detect type of image. We found infoImg[2]='.$infoImg[2], LOG_WARNING);
return 0;
}
// Initialisation des dimensions de la vignette si elles sont superieures a l'original // Initialisation des dimensions de la vignette si elles sont superieures a l'original
if($maxWidth > $imgWidth){ $maxWidth = $imgWidth; } if($maxWidth > $imgWidth){ $maxWidth = $imgWidth; }
@ -426,7 +439,7 @@ function vignette($file, $maxWidth = 160, $maxHeight = 120, $extName='_small', $
if (empty($targetformat)) $targetformat=$infoImg[2]; if (empty($targetformat)) $targetformat=$infoImg[2];
// Create empty image // Create empty image
if ($targetformat == 1) if ($targetformat == IMAGETYPE_GIF)
{ {
// Compatibilite image GIF // Compatibilite image GIF
$imgThumb = imagecreate($thumbWidth, $thumbHeight); $imgThumb = imagecreate($thumbWidth, $thumbHeight);
@ -451,25 +464,30 @@ function vignette($file, $maxWidth = 160, $maxHeight = 120, $extName='_small', $
// Initialisation des variables selon l'extension de l'image // Initialisation des variables selon l'extension de l'image
switch($targetformat) switch($targetformat)
{ {
case 1: // Gif case IMAGETYPE_GIF: // 1
$trans_colour = imagecolorallocate($imgThumb, 255, 255, 255); // On procede autrement pour le format GIF $trans_colour = imagecolorallocate($imgThumb, 255, 255, 255); // On procede autrement pour le format GIF
imagecolortransparent($imgThumb,$trans_colour); imagecolortransparent($imgThumb,$trans_colour);
$extImgTarget = '.gif'; $extImgTarget = '.gif';
$newquality='NU'; $newquality='NU';
break; break;
case 2: // Jpg case IMAGETYPE_JPEG: // 2
$trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 0); $trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 0);
$extImgTarget = '.jpg'; $extImgTarget = '.jpg';
$newquality=$quality; $newquality=$quality;
break; break;
case 3: // Png case IMAGETYPE_PNG: // 3
imagealphablending($imgThumb,false); // Pour compatibilite sur certain systeme imagealphablending($imgThumb,false); // Pour compatibilite sur certain systeme
$trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 127); // Keep transparent channel $trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 127); // Keep transparent channel
$extImgTarget = '.png'; $extImgTarget = '.png';
$newquality=$quality-100; $newquality=$quality-100;
$newquality=round(abs($quality-100)*9/100); $newquality=round(abs($quality-100)*9/100);
break; break;
case 4: // Bmp case IMAGETYPE_BMP: // 6
// Not supported by PHP GD
$extImgTarget = '.bmp';
$newquality='NU';
break;
case IMAGETYPE_WBMP: // 15
$trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 0); $trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 0);
$extImgTarget = '.bmp'; $extImgTarget = '.bmp';
$newquality='NU'; $newquality='NU';
@ -492,16 +510,19 @@ function vignette($file, $maxWidth = 160, $maxHeight = 120, $extName='_small', $
// Create image on disk // Create image on disk
switch($targetformat) switch($targetformat)
{ {
case 1: // Gif case IMAGETYPE_GIF: // 1
imagegif($imgThumb, $imgThumbName); imagegif($imgThumb, $imgThumbName);
break; break;
case 2: // Jpg case IMAGETYPE_JPEG: // 2
imagejpeg($imgThumb, $imgThumbName, $newquality); imagejpeg($imgThumb, $imgThumbName, $newquality);
break; break;
case 3: // Png case IMAGETYPE_PNG: // 3
imagepng($imgThumb, $imgThumbName, $newquality); imagepng($imgThumb, $imgThumbName, $newquality);
break; break;
case 4: // Bmp case IMAGETYPE_BMP: // 6
// Not supported by PHP GD
break;
case IMAGETYPE_WBMP: // 15
image2wmp($imgThumb, $imgThumbName); image2wmp($imgThumb, $imgThumbName);
break; break;
} }