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
|
function redim($lejpg,$im_dest) {
$size = getimagesize($lejpg);
$src_w = $size[0];
$src_h = $size[1];
$dst_w = 600; // Contraint le rééchantillonage à une largeur fixe
$dst_h = round(($dst_w / $src_w) * $src_h); // Maintient le ratio de l'image
$ext = strtolower(substr($lejpg, strrpos($lejpg, '.') + 1));
if(($ext=="jpg")||($ext=="jpeg"))
{
$dst_im = imagecreatetruecolor($dst_w,$dst_h); // Crée une nouvelle image en couleurs vraies (librairie GD)
$src_im = imagecreatefromjpeg($lejpg); //Crée une nouvelle image à partir d'un fichier ou d'une URL
imagecopyresampled($dst_im,$src_im,0,0,0,0,$dst_w,$dst_h,$src_w,$src_h); //rééchantillonne une image
imagejpeg($dst_im,$im_dest); //imagejpeg Envoie une image JPEG vers un navigateur ou un fichier
}
elseif (($ext=="png")) {
$dst_im = imagecreatetruecolor($dst_w,$dst_h); // Crée une nouvelle image en couleurs vraies (librairie GD)
$src_im = imagecreatefrompng($lejpg);
(imagealphablending($dst_im, false)) ;
(imagesavealpha($dst_im, true));
imagecolortransparent($dst_im,imagecolorallocate($dst_im,255,0,0));
imagecopyresampled($dst_im,$src_im,0,0,0,0,$dst_w,$dst_h,$src_w,$src_h);
imagepng($dst_im,$im_dest);
}
imagedestroy($dst_im); //imagedestroy Détruit une image
imagedestroy($src_im);
} |