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
|
$ratiobig = 400;
$tableau = @getimagesize($_FILES['image']['tmp_name']);
// si notre image est de type jpeg
if ($tableau[2] == 2) {
$src = imagecreatefromjpeg($_FILES['image']['tmp_name']);
// on teste si notre image est de type paysage ou portrait
if ($tableau[0] > $tableau[1]) {
$im = imagecreatetruecolor(round(($ratiobig/$tableau[1])*$tableau[0]), $ratiobig);
imagecopyresampled($im, $src, 0, 0, 0, 0, round(($ratiobig/$tableau[1])*$tableau[0]), $ratiobig, $tableau[0], $tableau[1]);
imagejpeg ($im, $dest_dossier.'/'.$_FILES['image']['name']);}
else {
$im2 = imagecreatetruecolor($ratiobig, round(($ratiobig/$tableau[0])*$tableau[1]));
imagecopyresampled($im2, $src, 0, 0, 0, 0, $ratiobig, round($tableau[1]*($ratiobig/$tableau[0])), $tableau[0], $tableau[1]);
imagejpeg ($im2, $dest_dossier.'/'.$_FILES['image']['name']);}
// on copie notre fichier généré dans le répertoire des miniatures
}
elseif ($tableau[2] == 3) {
$src = imagecreatefrompng($_FILES['image']['tmp_name']);
if ($tableau[0] > $tableau[1]) {
$im = imagecreatetruecolor(round(($ratiobig/$tableau[1])*$tableau[0]), $ratiobig);
imagecopyresampled($im, $src, 0, 0, 0, 0, round(($ratiobig/$tableau[1])*$tableau[0]), $ratiobig, $tableau[0], $tableau[1]);
imagepng ($im, $dest_dossier.'/'.$_FILES['image']['name']);}
else {
$im2 = imagecreatetruecolor($ratiobig, round(($ratiobig/$tableau[0])*$tableau[1]));
imagecopyresampled($im2, $src, 0, 0, 0, 0, $ratiobig, round($tableau[1]*($ratiobig/$tableau[0])), $tableau[0], $tableau[1]);
imagepng ($im2, $dest_dossier.'/'.$_FILES['image']['name']); }
} |
Partager