IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

EDI, CMS, Outils, Scripts et API PHP Discussion :

[Galerie] Galerie automatique d'images


Sujet :

EDI, CMS, Outils, Scripts et API PHP

  1. #1
    Candidat au Club
    Homme Profil pro
    Développeur Web
    Inscrit en
    Août 2018
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 52
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Août 2018
    Messages : 8
    Points : 3
    Points
    3
    Par défaut [Galerie] Galerie automatique d'images
    Bonjour à tous

    Je suis graphiste, et codeur HTML CSS, mais malheureusement pas PHP...
    J'ai crée avec des bouts de code trouvés ici et la, une page qui génére une galerie automatique d'image.
    la page fonctionne pas mal, et (important pour moi) reste élégante (lightbox, responsive...).

    Mais elle ne classe pas les fichiers correctement, ils ne sont pas classés par ordres alphanumérique.
    j'ai fait des tests avec différents codes sans succès, mes talents de programmeur PHP sont pas terribles.
    Si quelqu'un pourrais m'aider ce serait top.

    et si en plus le script pourrait créer de lui même les vignettes, la on serait pas loin du paradis !

    Merci pour votre aide !

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    <!doctype html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
     
    <title>Photo Gallery Directory</title>
     
     
    <!-- lightbox-Directory -->
    <link href='https://cdnjs.cloudflare.com/ajax/libs/simplelightbox/1.13.0/simplelightbox.min.css' rel='stylesheet' type='text/css'>
     
     
    <style type="text/css">
     
    @import url('https://fonts.googleapis.com/css?family=Montserrat:200,300,400,500,600,800,900');
     
     
    html {
      height: 100%;
     
    }
     
    body {
    	margin-left: 0px;
    	margin-top: 0px;
    	margin-right: 0px;
    	margin-bottom: 0px;
    	height: 100%;
    	background-color: #E0E0E0;
    	}
     
     
    .X1conteneur { 
    	margin:5% 0%; /* espacement horizontal entre les blocs */
    	width:100%;
    	display:inline-block;
    	vertical-align:middle;
    	text-align:center; /* on rétablit l'alignement du texte */ 
    	  font-family: 'Montserrat', sans-serif;
      font-size: 30px;
      font-weight: 300;
    }
     
    .X2conteneurs { 
    	padding:10px; /* aération interne des blocs */
    	margin:auto; /* espacement horizontal entre les blocs */
    	width:40%;
    	display:inline-block;
    	text-align:left; /* on rétablit l'alignement du texte */ 
    	vertical-align: middle;
    }
     
     
    .X3conteneurs { 
    	padding:10px; /* aération interne des blocs */
    	margin:0 10px; /* espacement horizontal entre les blocs */
    	width:30%;
    	display:inline-block;
    	vertical-align:middle;
    	text-align:left; /* on rétablit l'alignement du texte */ 
    }
     
    #myBtn {
      display: none;
      position: fixed;
      bottom: 20px;
      right: 30px;
      z-index: 99;
      font-size: 18px;
      border: none;
      outline: none;
      background-color: rgba(201, 76, 76, 0.3);
      color: white;
      cursor: pointer;
      padding: 15px;
      border-radius: 4px;
    }
     
    #myBtn:hover {
      background-color: #555;
    }
     
     
    	@charset "utf-8";
    /* CSS Document */
     
     
    	.pgd-container {
      height:auto;
    	overflow: hidden;
    	top:0px;
    	left:0px;
    	width: 80%; margin:0px auto; 
      position: relative;
      text-align:center;
    }
     
     
     .pgd-gallery a img {
      width: 200px; 
      height: 200px; 
      margin:0.2em 0.2em;
      vertical-align:middle;
      display:inline-block;
      border: solid 2px #fff; 
      overflow: hidden; 
      position: relative;
      text-align:left;
      transition: all .2s ease-out;
    }
     
     
     
     
    .pgd-gallery img {
      width: 100%;
      height: 100%;
      max-height: 100%;
      max-width: 100%;
      object-fit: cover;
      }
     
    .pgd-container .pgd-gallery a:hover img {
      -webkit-transform: scale(1.05);
      -moz-transform: scale(1.05);
      -o-transform: scale(1.05);
      -ms-transform: scale(1.05);
      transform: scale(1.05);
      transition: all .2s ease-out;
      z-index: 1;
     
    }
     
    .pgd-clear {
      clear: both;
      float: none;
      width: 100%;
    }
     
     
     
    /******************************************************************************************************* Responsive */
     
    @media screen and (max-width: 800px) {
     
     .pgd-gallery a img {
      width: 100px;
      height: 100px;
    }
     
    	}
     
     
    </style>
     
     
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/simplelightbox/1.13.0/simple-lightbox.js"></script>
    <script type="text/javascript" src="http://www.agence-casanova.fr/Scripts/Photo-Gallery-Directory/Photo-Gallery-Directory.js"></script>
     
     
    </head>
     
    <body>
     
    <div class="X1conteneur">
    <a class="h9" >Gallery</a><br>
    <a class="b2" href="<?php echo $_SERVER['HTTP_REFERER']; ?>">‹ Retour</a>
    </div>
     
     
    <div class='pgd-container'>
     <div class="pgd-gallery">
     
      <?php 
      // Image extensions
      $image_extensions = array("jpeg","JPEG","jpg","JPG","png","PNG","gif","GIF");
     
      // Target directory
      $dir = 'images/';
      if (is_dir($dir)){
     
       if ($dh = opendir($dir)){
        $count = 1;
     
        // Read files
        while (($file = readdir($dh)) !== false){
     
         if($file != '' && $file != '.' && $file != '..'){
     
          // Thumbnail image path
          $thumbnail_path = "images/thumbs".$file;
     
          // Image path
          $image_path = "images/".$file;
     
          $thumbnail_ext = pathinfo($thumbnail_path, PATHINFO_EXTENSION);
          $image_ext = pathinfo($image_path, PATHINFO_EXTENSION);
     
          // Check its not folder and it is image file
          if(!is_dir($image_path) && 
             in_array($thumbnail_ext,$image_extensions) && 
             in_array($image_ext,$image_extensions)){
       ?>
     
           <!-- Image -->
           <a href="<?php echo $image_path; ?>">
            <img src="<?php echo $thumbnail_path; ?>" alt="" title=""/>
           </a>
           <!-- --- -->
           <?php
     
           // Break
           if( $count%100 == 0){
           ?>
             <div class="pgd-clear"></div>
           <?php 
           }
           $count++;
          }
         }
     
        }
        closedir($dh);
       }
      }
     ?>
     </div>
    </div>
     
    <div class="X1conteneur">
    <a href="<?php echo $_SERVER['HTTP_REFERER']; ?>">‹ Retour</a>
     
    </div>
     
     
    <button onclick="topFunction()" id="myBtn" title="Go to top">Top</button>
     
     
    <script>
    // When the user scrolls down 20px from the top of the document, show the button
    window.onscroll = function() {scrollFunction()};
     
    function scrollFunction() {
        if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
            document.getElementById("myBtn").style.display = "block";
        } else {
            document.getElementById("myBtn").style.display = "none";
        }
    }
     
    // When the user clicks on the button, scroll to the top of the document
    function topFunction() {
        document.body.scrollTop = 0;
        document.documentElement.scrollTop = 0;
    }
    </script>
     
     
     
    </body>
    </html>

  2. #2
    Membre émérite
    Avatar de badaze
    Homme Profil pro
    Chef de projets info
    Inscrit en
    Septembre 2002
    Messages
    1 412
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ain (Rhône Alpes)

    Informations professionnelles :
    Activité : Chef de projets info
    Secteur : Transports

    Informations forums :
    Inscription : Septembre 2002
    Messages : 1 412
    Points : 2 522
    Points
    2 522
    Par défaut
    Essaie comme ça. A peine testé.

    Le principe est de remplir un array avec les noms des fichiers du répertoire puis de le trier dans l'ordre "naturel" qui va au-delà de l'ordre alphabétique.
    Une fois trié on parcourt l'array afin d'afficher les images.

    Code php : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
     
    <!doctype html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
     
    <title>Photo Gallery Directory</title>
     
     
    <!-- lightbox-Directory -->
    <link href='https://cdnjs.cloudflare.com/ajax/libs/simplelightbox/1.13.0/simplelightbox.min.css' rel='stylesheet' type='text/css'>
     
     
    <style type="text/css">
     
    @import url('https://fonts.googleapis.com/css?family=Montserrat:200,300,400,500,600,800,900');
     
     
    html {
      height: 100%;
     
    }
     
    body {
     margin-left: 0px;
     margin-top: 0px;
     margin-right: 0px;
     margin-bottom: 0px;
     height: 100%;
     background-color: #E0E0E0;
     }
     
     
    .X1conteneur { 
     margin:5% 0%; /* espacement horizontal entre les blocs */
     width:100%;
     display:inline-block;
     vertical-align:middle;
     text-align:center; /* on rétablit l'alignement du texte */ 
       font-family: 'Montserrat', sans-serif;
      font-size: 30px;
      font-weight: 300;
    }
     
    .X2conteneurs { 
     padding:10px; /* aération interne des blocs */
     margin:auto; /* espacement horizontal entre les blocs */
     width:40%;
     display:inline-block;
     text-align:left; /* on rétablit l'alignement du texte */ 
     vertical-align: middle;
    }
     
     
    .X3conteneurs { 
     padding:10px; /* aération interne des blocs */
     margin:0 10px; /* espacement horizontal entre les blocs */
     width:30%;
     display:inline-block;
     vertical-align:middle;
     text-align:left; /* on rétablit l'alignement du texte */ 
    }
     
    #myBtn {
      display: none;
      position: fixed;
      bottom: 20px;
      right: 30px;
      z-index: 99;
      font-size: 18px;
      border: none;
      outline: none;
      background-color: rgba(201, 76, 76, 0.3);
      color: white;
      cursor: pointer;
      padding: 15px;
      border-radius: 4px;
    }
     
    #myBtn:hover {
      background-color: #555;
    }
     
     
     @charset "utf-8";
    /* CSS Document */
     
     
     .pgd-container {
      height:auto;
     overflow: hidden;
     top:0px;
     left:0px;
     width: 80%; margin:0px auto; 
      position: relative;
      text-align:center;
    }
     
     
     .pgd-gallery a img {
      width: 200px; 
      height: 200px; 
      margin:0.2em 0.2em;
      vertical-align:middle;
      display:inline-block;
      border: solid 2px #fff; 
      overflow: hidden; 
      position: relative;
      text-align:left;
      transition: all .2s ease-out;
    }
     
     
     
     
    .pgd-gallery img {
      width: 100%;
      height: 100%;
      max-height: 100%;
      max-width: 100%;
      object-fit: cover;
      }
     
    .pgd-container .pgd-gallery a:hover img {
      -webkit-transform: scale(1.05);
      -moz-transform: scale(1.05);
      -o-transform: scale(1.05);
      -ms-transform: scale(1.05);
      transform: scale(1.05);
      transition: all .2s ease-out;
      z-index: 1;
     
    }
     
    .pgd-clear {
      clear: both;
      float: none;
      width: 100%;
    }
     
     
     
    /******************************************************************************************************* Responsive */
     
    @media screen and (max-width: 800px) {
     
     .pgd-gallery a img {
      width: 100px;
      height: 100px;
    }
     
     }
     
     
    </style>
     
     
    <script src="<a href="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script" target="_blank">https://ajax.googleapis.com/ajax/lib...n.js"></script</a>>
    <script type="text/javascript" src="<a href="https://cdnjs.cloudflare.com/ajax/libs/simplelightbox/1.13.0/simple-lightbox.js"></script" target="_blank">https://cdnjs.cloudflare.com/ajax/li...x.js"></script</a>>
    <script type="text/javascript" src="<a href="http://www.agence-casanova.fr/Scripts/Photo-Gallery-Directory/Photo-Gallery-Directory.js"></script" target="_blank">http://www.agence-casanova.fr/Script...y.js"></script</a>>
     
     
    </head>
     
    <body>
     
    <div class="X1conteneur">
    <a class="h9" >Gallery</a><br>
    <a class="b2" href="<?php echo $_SERVER['HTTP_REFERER']; ?>">‹ Retour</a>
    </div>
     
     
    <div class='pgd-container'>
     <div class="pgd-gallery">
     
      <?php 
      // Image extensions
      $image_extensions = array("jpeg","JPEG","jpg","JPG","png","PNG","gif","GIF");
     
      // Target directory
      $dir = 'images/';
      if (is_dir($dir)){
     
       if ($dh = opendir($dir)){
     
        // Read files
     $fileList = array();
        while (($file = readdir($dh)) !== false){
     
         if($file != '' && $file != '.' && $file != '..'){
      $fileList[] = strtolower($file);
      }
     }
     closedir($dh);
     //---- Tri dans l'ordre naturel
     natsort($fileList);
     
     
     $count = 1;
     foreach ($fileList as $file) {
     
          // Thumbnail image path
          $thumbnail_path = "images/thumbs".$file;
     
          // Image path
          $image_path = "images/".$file;
     
          $thumbnail_ext = pathinfo($thumbnail_path, PATHINFO_EXTENSION);
          $image_ext     = pathinfo($image_path, PATHINFO_EXTENSION);
     
          // Check its not folder and it is image file
          if(!is_dir($image_path) && 
             in_array($thumbnail_ext,$image_extensions) && 
             in_array($image_ext,$image_extensions)){
       ?>
     
           <!-- Image -->
           <a href="<?php echo $image_path; ?>">
            <img src="<?php echo $thumbnail_path; ?>" alt="" title=""/>
           </a>
           <!-- --- -->
           <?php
     
           // Break
           if( $count%100 == 0){
           ?>
             <div class="pgd-clear"></div>
           <?php 
           }
           $count++;
          } 
        }
     
       }
      }
     ?>
     </div>
    </div>
     
    <div class="X1conteneur">
    <a href="<?php echo $_SERVER['HTTP_REFERER']; ?>">‹ Retour</a>
     
    </div>
     
     
    <button onclick="topFunction()" id="myBtn" title="Go to top">Top</button>
     
     
    <script>
    // When the user scrolls down 20px from the top of the document, show the button
    window.onscroll = function() {scrollFunction()};
     
    function scrollFunction() {
        if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
            document.getElementById("myBtn").style.display = "block";
        } else {
            document.getElementById("myBtn").style.display = "none";
        }
    }
     
    // When the user clicks on the button, scroll to the top of the document
    function topFunction() {
        document.body.scrollTop = 0;
        document.documentElement.scrollTop = 0;
    }
    </script>
     
     
     
    </body>
    </html>
    Cela ne sert à rien d'optimiser quelque chose qui ne fonctionne pas.

    Mon site : www.emmella.fr

    Je recherche le manuel de l'Olivetti Logos 80B.

  3. #3
    Candidat au Club
    Homme Profil pro
    Développeur Web
    Inscrit en
    Août 2018
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 52
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Août 2018
    Messages : 8
    Points : 3
    Points
    3
    Par défaut
    MErci pour ton aide Badaze,

    Ton script fonctionne dans l'absolu, les images sont classées dans l'ordre alphanumerique..
    Mais il y a un bug, les majuscules et minuscules ne sont pas respectées...
    Par exemple si le nom de l'image est ../IMAGE1.JPG l'image ne s'affiche pas... car le lien donnera sur ../image1.jpg

    Donc la galerie ne s'affiche pas.

    on est pas loin de la solution...

  4. #4
    Membre émérite
    Avatar de badaze
    Homme Profil pro
    Chef de projets info
    Inscrit en
    Septembre 2002
    Messages
    1 412
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ain (Rhône Alpes)

    Informations professionnelles :
    Activité : Chef de projets info
    Secteur : Transports

    Informations forums :
    Inscription : Septembre 2002
    Messages : 1 412
    Points : 2 522
    Points
    2 522
    Par défaut
    Essaie comme ça. On ne sais jamais.

    Remplace
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    $fileList[] = strtolower($file);
    Par
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    $fileList[$file] = strtolower($file);
    et

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    foreach ($fileList as $file)
    par
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    foreach ($fileList as $file => $filelow)
    Cela ne sert à rien d'optimiser quelque chose qui ne fonctionne pas.

    Mon site : www.emmella.fr

    Je recherche le manuel de l'Olivetti Logos 80B.

  5. #5
    Candidat au Club
    Homme Profil pro
    Développeur Web
    Inscrit en
    Août 2018
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 52
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Août 2018
    Messages : 8
    Points : 3
    Points
    3
    Par défaut
    Nickel !! Merci beaucoup !!

Discussions similaires

  1. php Galerie photos : Erreur upload images
    Par hx.jonathan dans le forum Langage
    Réponses: 1
    Dernier message: 11/08/2010, 15h01
  2. Galerie : chargement d'une image et alignement des boutons
    Par terry90 dans le forum Mise en page CSS
    Réponses: 3
    Dernier message: 25/06/2009, 19h21
  3. Redimensionnement automatique d'images
    Par Ant8386 dans le forum Balisage (X)HTML et validation W3C
    Réponses: 5
    Dernier message: 27/08/2007, 10h03
  4. Réaliser une galerie photo automatique sans php
    Par vallica dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 01/10/2006, 10h57
  5. [POO] Class Défilementa automatique d'images avec animation
    Par rakoto.n dans le forum Général JavaScript
    Réponses: 9
    Dernier message: 14/01/2005, 18h21

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo