| 12
 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
 
 | function creerMiniatures($dossierOriginal,$largeur,$hauteur,$dossierDest){
    $i=0;
    if ($dir = opendir($dossierOriginal)) {
        while($file = readdir($dir)) {
            $parts = explode(".",$file);
            $points = count($parts);
            $points --;
            $ext = strtolower($parts[$points]);
            if($ext == "jpg" || $ext == "jpeg"){
                $str = 'mini_'.$file;
                if(!file_exists($str) && substr($file,0,5) != "mini_"){
                    $fichierSource = $file;
                    $largeurDestination = $largeur;
                    $hauteurDestination = $hauteur;
                    $im = ImageCreateTrueColor ($largeurDestination, $hauteurDestination)
                    or die ("Erreur lors de la création de l'image");
                    $source = ImageCreateFromJpeg($fichierSource);
                    $largeurSource = imagesx($source);
                    $hauteurSource = imagesy($source);
                    $blanc = ImageColorAllocate ($im, 255, 255, 255);
                    ImageCopyResized($im,$source,0,0,0,0,$largeurDestination,$hauteurDestination,$largeurSource,$hauteurSource);
                    ImageString($im, 0, 12, $hauteurDestination-18, "$fichierSource - ($largeurSource x $hauteurSource)", $blanc);
                    $miniature = "$dossierDest/mini_$fichierSource";
                    ImageJpeg ($im, $miniature);
                    $i++;
                    if($i==10) {
                        return false;
                    }
                }
            }
        }
        return true;
        closedir($dir); // fermeture du dossier
    }
 
} | 
Partager