logotype

Connexion

Crée une miniature à partir d'une image jpg, gif ou png

$directory = "./photos";
$newImage = "ciel.jpg"; //La  nouvelle image
$extension = strrchr($newImage, '.'); //Récupère l'extension
$nomImage = substr($newImage, strrpos($newImage, '/') + 1, - strlen($extension)); //Récupère le nom de l'image
if(!file_exists($directory. "tets_Mini.jpg"))       //Si il n'y a a pas de miniature
    CreeMiniature($newImage, $directory . $nomImage . "_Mini" . $extension, 80); //Appel la fonction pour créer la miniature. 

function CreeMiniature($newImage, $miniImage, $largeur, $qualite = 90)
{
     $Ext_Image = strrchr($newImage, ".");
     list($width, $height) = getimagesize($newImage);
     $percent = ($width / $largeur);
     $X_New      = $largeur;
     $Y_New      = $height / $percent;
     $Mini      = imagecreatetruecolor($X_New, $Y_New);

     switch(strtolower($Ext_Image))
     {
        case '.jpg' :
            $Img = imagecreatefromjpeg($newImage);
            imagecopyresized($Mini, $Img, 0,0,0,0,$X_New,$Y_New,$width,$height);
            imagejpeg($Mini, $miniImage, $qualite);
        break;
        case '.gif':
            $Img = imagecreatefromgif($newImage);
            imagecopyresized($Mini, $Img, 0,0,0,0,$X_New,$Y_New,$width,$height);
             imagegif($Mini, $miniImage, $qualite);
        break;
        case '.png':
            $Img = imagecreatefrompng($newImage);
            imagecopyresized($Mini, $Img, 0,0,0,0,$X_New,$Y_New,$width,$height);
             imagepng($Mini, $miniImage, $qualite);
        break;
        default:
            imagedestroy($Mini);
            return false;
    }
     imagedestroy($Mini);
     imagedestroy($Img);
     return true;
}

You have no rights to post comments