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
|
if (move_uploaded_file($_FILES['up_photo']['tmp_name'], $dest_dossier . $dest_fichier)) // à ce moment on met le fichier sur le serveur
{
// Creation de l'image miniature
// si notre image est de type jpeg
if ($tableau[2] == 2)
{
// on crée une image à partir de notre grande image à l'aide de la librairie GD
$src = imagecreatefromjpeg($dest_dossier.'/'.$dest_fichier);
// on teste si notre image est de type paysage ou portrait
if ($tableau[0] > $tableau[1])
{
$im = imagecreatetruecolor(round(($ratio/$tableau[1])*$tableau[0]), $ratio);
imagecopyresampled($im, $src, 0, 0, 0, 0, round(($ratio/$tableau[1])*$tableau[0]), $ratio, $tableau[0], $tableau[1]);
}
else
{
$im = imagecreatetruecolor($ratio, round(($ratio/$tableau[0])*$tableau[1]));
imagecopyresampled($im, $src, 0, 0, 0, 0, $ratio, round($tableau[1]*($ratio/$tableau[0])), $tableau[0], $tableau[1]);
}
// on copie notre fichier généré dans le répertoire des miniatures
imagejpeg ($im, $dest_dossier_mini.'/'.$dest_fichier);
}
if ($tableau[2] == 3)
{
$src = imagecreatefrompng($dir.'/'.$file_upload);
if ($tableau[0] > $tableau[1])
{
$im = imagecreatetruecolor(round(($ratio/$tableau[1])*$tableau[0]), $ratio);
imagecopyresampled($im, $src, 0, 0, 0, 0, round(($ratio/$tableau[1])*$tableau[0]), $ratio, $tableau[0], $tableau[1]);
}
else
{
$im = imagecreatetruecolor($ratio, round(($ratio/$tableau[0])*$tableau[1]));
imagecopyresampled($im, $src, 0, 0, 0, 0, $ratio, round($tableau[1]*($ratio/$tableau[0])), $tableau[0], $tableau[1]);
}
imagepng ($im, $dir_mini.'/'.$file_upload);
} |
Partager