1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
$miniature = $dossier.$file_name.'_m.'.$extension;
copy($fullpath, $miniature);
switch($extension){
case ($extension=="jpeg" || $extension=="jpg"):
$function_image_create = "ImageCreateFromJPEG";
$function_image_new = "ImageJpeg";
break;
case "png":
$function_image_create = "ImageCreateFromPng";
$function_image_new = "ImagePNG";
break;
case "gif":
$function_image_create = "ImageCreateFromGif";
$function_image_new = "ImageGif";
break;
default:
echo '<script>alert("Ce n\'est pas un fichier image !'.$extension.'");</script>' ;
exit;
break;
}
list($width, $height) = getimagesize($miniature); // on récupère les dimensions de l'image
$sizemax_min = "130";
// si l'un des côté est supérieur à $sizemax, on redimensionne en conservant les proportions
if ($width>$sizemax_min || $height>$sizemax_min) {
$ratio = $height/$width;
$newheight = ($height > $width) ? $sizemax_min : $sizemax_min*$ratio;
$newwidth = $newheight/$ratio;
$thumb = ImageCreateTrueColor($newwidth,$newheight);
$source = @$function_image_create($miniature);
ImageCopyResampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
@$function_image_new($thumb,$miniature);
} |
Partager