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
| function resizePhoto($name_filephoto, $photoDir, $photoLargeurMax, $photoHauteurMax, $prefixePhoto, $hauteurFixe = '', $largeurFixe = '') {
$image = $name_filephoto;
$source = $photoDir;
$destination = $photoDir;
$size = getimagesize($source.$image);
$largeur_src=$size[0];
$hauteur_src=$size[1];
$image_src=imagecreatefromjpeg($source.$image);
$ratio = ajoutPhoto::ratio($photoLargeurMax, $photoHauteurMax, $largeur_src, $hauteur_src, $hauteurFixe, $largeurFixe);
if($ratio!=1) { // si ratio != 1
$image_dest=imagecreatetruecolor(round($largeur_src*$ratio), round($hauteur_src*$ratio));
imagecopyresampled($image_dest,$image_src,0,0,0,0,round($largeur_src*$ratio),round($hauteur_src*$ratio),$largeur_src,$hauteur_src);
imagedestroy($image_src);
if(!imagejpeg($image_dest, $destination.$prefixePhoto.$image)){
$result = "<p>le dimensionnement de la photo $image a échoué. Réessayez dans quelques minutes. Si le problème persiste, contactez le webmaster.<br />destination = ".$destination.$prefixePhoto.$image."</p> \n <hr /> \n ";
}
else {
imagedestroy($image_dest);
chmod($destination.$prefixePhoto.$image, 0775);
$result = "<p>Photo $image redimensionnée </p> \n";
}
}
else { // si ratio = 1
chmod($destination.$prefixePhoto.$image, 0775);
$result = "<p>la photo est au format, elle n'a pas été redimensionnée.</p> \n <hr /> \n ";
}
echo $result;
} |
Partager