$file, 'width' => $taille_image[0], 'height' => $taille_image[1], 'size' => $size ); } } } } return $images; } function scandir( $DIR, $width, $height ) { global $HTTP_POST_VARS, $conf, $output; $compteur = 0; $temps = array(); if ( $ODIR = opendir( $DIR ) ) { while ( $FILE = readdir ( $ODIR ) ) { $TMP = $DIR."/".$FILE; if ( is_image ( $TMP, true ) ) { if ( $compteur < $HTTP_POST_VARS['n'] && !TN_exist( $DIR, $FILE ) ) { $t1 = explode( " ", microtime() ); $t2 = explode( ".", $t1[0] ); $t2 = $t1[1].".".$t2[1]; $info = RatioResizeImg( $FILE, $width, $height, $DIR."/", "jpg" ); $t3 = explode( " ", microtime() ); $t4 = explode( ".", $t3[0] ); $t4 = $t3[1].".".$t4[1]; $info['temps'] = ( $t4 - $t2 ) * 1000; $temps[$compteur++] = $info; //$output.= " (".number_format( $temps[$compteur-1], 2, '.', ' ')." ms)
";; } } } } return $temps; } function RatioResizeImg( $image, $newWidth, $newHeight, $path, $extension) { global $conf, $HTTP_POST_VARS; // chemin complet de l'image : $chemin = $path.$image; // détéction du type de l'image eregi( "(...)$", $chemin, $regs); $type = $regs[1]; switch( $type ) { case "jpg": $srcImage = @imagecreatefromjpeg( $chemin ); break; case "JPG": $srcImage = @imagecreatefromjpeg( $chemin ); break; case "png": $srcImage = @imagecreatefrompng( $chemin ); break; case "PNG": $srcImage = @imagecreatefrompng( $chemin ); break; default : unset( $type ); break; } if( $srcImage ) { // hauteurs/largeurs $srcWidth = imagesx( $srcImage ); $srcHeight = imagesy( $srcImage ); $ratioWidth = $srcWidth/$newWidth; $ratioHeight = $srcHeight/$newHeight; // taille maximale dépassée ? if (($ratioWidth > 1) || ($ratioHeight > 1)) { if( $ratioWidth < $ratioHeight) { $destWidth = $srcWidth/$ratioHeight; $destHeight = $newHeight; } else { $destWidth = $newWidth; $destHeight = $srcHeight/$ratioWidth; } } else { $destWidth = $srcWidth; $destHeight = $srcHeight; } // selon votre version de GD installée sur le serveur hébergeur if ( $HTTP_POST_VARS['gd'] == 2 ) { // Partie 1 : GD 2.0 ou supérieur, résultat très bons $destImage = imagecreatetruecolor( $destWidth, $destHeight); imagecopyresampled( $destImage, $srcImage, 0, 0, 0, 0, $destWidth,$destHeight,$srcWidth,$srcHeight ); } else { // Partie 2 : GD inférieur à 2, résultat très moyens $destImage = imagecreate( $destWidth, $destHeight); imagecopyresized( $destImage, $srcImage, 0, 0, 0, 0, $destWidth,$destHeight,$srcWidth,$srcHeight ); } if( !is_dir( $path."thumbnail" ) ) { umask(0000); mkdir( $path."thumbnail", 0777 ); } $dest_file = $path."thumbnail/".$conf['prefix_thumbnail'].substr ( $image, 0, strrpos ( $image, ".") ).".".$extension; // création et sauvegarde de l'image finale imagejpeg($destImage, $dest_file); // libère la mémoire imagedestroy( $srcImage ); imagedestroy( $destImage ); // renvoit l'URL de l'image //return $dest_file; $taille_image = getimagesize( $chemin ); $size = number_format( floor ( filesize( $chemin ) / 1024 ), 0, '', ' ')." KB"; $tn_taille_image = getimagesize( $dest_file ); $tn_size = number_format( floor ( filesize( $dest_file ) ), 0, '', ' ')." octets"; $info = array( 'name' => $image, 'width' => $taille_image[0], 'height' => $taille_image[1], 'size' => $size, 'tn_name' => $conf['prefix_thumbnail'].substr ( $image, 0, strrpos ( $image, ".") ).".".$extension, 'tn_width' => $tn_taille_image[0], 'tn_height' => $tn_taille_image[1], 'tn_size' => $tn_size ); return $info; } // erreur else { echo $lang['tn_no_support']." "; if ($type) { echo $lang['tn_format']." $type"; } else { echo $lang['tn_thisformat']; } exit(); } } function array_max( $array ) { $max = 0; for ( $i = 0; $i < sizeof( $array ); $i++ ) { if ( $array[$i] > $max ) { $max = $array[$i]; } } return $max; } function array_min( $array ) { $min = 99999999999999; for ( $i = 0; $i < sizeof( $array ); $i++ ) { if ( $array[$i] < $min ) { $min = $array[$i]; } } return $min; } function array_moy( $array ) { return array_sum( $array ) / sizeof( $array ); } // get_dirs retourne un tableau contenant tous les sous-répertoires d'un répertoire function get_displayed_dirs( $rep, $indent ) { global $conf,$lang; $sub_rep = array(); $i = 0; $dirs = ""; if ( $opendir = opendir ( $rep ) ) { while ( $file = readdir ( $opendir ) ) { if ( $file != "." && $file != ".." && is_dir ( $rep."/".$file ) && $file != "thumbnail" ) { $sub_rep[$i++] = $file; } } } // write of the dirs for ( $i = 0; $i < sizeof( $sub_rep ); $i++ ) { $images = get_images_without_thumbnail( $rep."/".$sub_rep[$i] ); $nb_picture_without_TN = sizeof( $images ); $dirs.= $indent; if ( $nb_picture_without_TN > 0 ) { $dirs.= ""; } $dirs.= "\">\"/".$sub_rep[$i]; if ( $nb_picture_without_TN > 0 ) { $dirs.= ""; } if ( $nb_picture_without_TN > 0 ) { $dirs.= " [ $nb_picture_without_TN ".$lang['tn_dirs_alone']." ]"; } $dirs.= "
"; $dirs.= get_displayed_dirs( $rep."/".$sub_rep[$i], $indent."        " ); } return $dirs; } $output = ""; if ( isset( $HTTP_GET_VARS['dir'] ) ) { //---------------vérification de la présence d'images sans thumbnail $images = get_images_without_thumbnail( $HTTP_GET_VARS['dir'] ); if ( sizeof( $images ) == 0 ) { $output.= "
[ 0 ".$lang['tn_dirs_alone']." ]
"; } else if ( isset( $HTTP_POST_VARS['submit'] ) ) { //----------------------------------------vérification des variables $nb_erreur = 0; $erreur = ""; if ( !ereg( "^[0-9]{2,3}$", $HTTP_POST_VARS['width'] ) || $HTTP_POST_VARS['width'] < 10 ) { $nb_erreur++; $erreur.= "
  • ".$lang['tn_err_width']." 10
  • "; } if ( !ereg( "^[0-9]{2,3}$", $HTTP_POST_VARS['height'] ) || $HTTP_POST_VARS['height'] < 10 ) { $nb_erreur++; $erreur.= "
  • ".$lang['tn_err_height']." 10
  • "; } if ( !isset( $HTTP_POST_VARS['gd'] ) ) { $nb_erreur++; $erreur.= "
  • ".$lang['tn_err_GD']."
  • "; } //---------------------------------------------listing des résultats if ( $nb_erreur == 0 ) { $style = "class=\"row2\" style=\"text-align:center;font-weight:bold;"; $output.= " "; $tab_infos = scandir( $HTTP_GET_VARS['dir'], $HTTP_POST_VARS['width'], $HTTP_POST_VARS['height'] ); for ( $i = 0; $i < sizeof ( $tab_infos ); $i++ ) { $temps[$i] = $tab_infos[$i]['temps']; } $max = array_max( $temps ); $min = array_min( $temps ); for ( $i = 0; $i < sizeof ( $tab_infos ); $i++ ) { $temps[$i] = $tab_infos[$i]['temps']; $num = $i + 1; $class = ""; if ( $i%2 == 1 ) { $class = "class=\"row2\""; } $output.= " "; } $output.= "
    ".$lang['tn_results_title']."
      ".$lang['tn_picture']." ".$lang['tn_filesize']." ".$lang['tn_width']." ".$lang['tn_height']." ".$lang['tn_results_gen_time']." ".$lang['thumbnail']." ".$lang['tn_filesize']." ".$lang['tn_width']." ".$lang['tn_height']."
    $num ".$tab_infos[$i]['name']." ".$tab_infos[$i]['size']." ".$tab_infos[$i]['width']." ".$tab_infos[$i]['height']."
    ".number_format( $tab_infos[$i]['temps'], 2, '.', ' ')." ms
    ".$tab_infos[$i]['tn_name']." ".$tab_infos[$i]['tn_size']." ".$tab_infos[$i]['tn_width']." ".$tab_infos[$i]['tn_height']."
     
    ".$lang['tn_stats']."
    ".$lang['tn_stats_nb']." : ".sizeof( $temps )."
    ".$lang['tn_stats_total']." : ".number_format( array_sum( $temps ), 2, '.', ' ')." ms
    ".$lang['tn_stats_max']." : ".number_format( $max, 2, '.', ' ')." ms
    ".$lang['tn_stats_min']." : ".number_format( $min, 2, '.', ' ')." ms
    ".$lang['tn_stats_mean']." : ".number_format( array_moy( $temps ), 2, '.', ' ')." ms
     
    "; } else { $output.= "
    ".$lang['tn_err']."
    "; } } //-------------------------------------paramètres de miniaturisation if ( sizeof( $images ) != 0 ) { $output.= " "; $output.= "
    "; $output.= " "; $output.= " "; $output.= "
    ".$lang['tn_params_title']."
     
    ".$lang['tn_params_GD']."
    2.x ".$lang['tn_params_GD_info']."
    ".$lang['tn_width']."
    ".$lang['tn_params_width_info']."
    ".$lang['tn_height']."
    ".$lang['tn_params_height_info']."
    ".$lang['tn_params_create']."
    ".$lang['tn_params_create_info']."
    ".$lang['tn_params_format']."
    jpeg ".$lang['tn_params_format_info']."
     
    "; //-----------------------------------liste des images sans miniature $images = get_images_without_thumbnail( $HTTP_GET_VARS['dir'] ); $style = "class=\"row2\" style=\"text-align:center;font-weight:bold;"; $output.= " "; for ( $i = 0; $i < sizeof( $images ); $i++ ) { $num = $i + 1; $class = ""; if ( $i%2 == 1 ) { $class = " class=\"row2\""; } $output.= " "; } $output.= "
    ".sizeof( $images )." ".$lang['tn_alone_title']."
      ".$lang['tn_picture']." ".$lang['tn_filesize']." ".$lang['tn_width']." ".$lang['tn_height']."
    ".$num."
    ".$images[$i]['name']."
    ".$images[$i]['size']."
    ".$images[$i]['width']."
    ".$images[$i]['height']."
    "; } } //-----------------------------------liste des répertoires //-------------------------si aucun répertoire selectionné else { $output = " "; $output.= "
    ".$lang['tn_dirs_title']."
    \"\"/galleries"; $output.= "
    "; $output.= get_displayed_dirs( "../galleries", "        " ); $output.= "
    "; } echo $output; ?>