- Published on
 
A simple PHP Gallery
- Authors
 
- Name
 - Arnaud Ferrand
 
"A very light gallery" whose purpose is to display a page with "thumbnail" of all the images in a directory.
This script makes it possible to list the files of the directory in which it is located; display images with a maximum border of 150 pixels; and show the original size of the image. Finally, a link on the image allows you to see the image in real size.
<?php
  // Afficher le dossier courant
  $folder=".";
  $dossier = opendir($folder);
  if ($dossier != false) {
    while($Fichier = readdir($dossier)) {
      // TODO : comment prendre en compte uniquement les fichiers images
      if ($Fichier != '.' && $Fichier != '..' && $Fichier != 'index.php' && $Fichier != 'image.php') {
        // Nom de l'image.
        $source=$Fichier;
        // Taille à ne pas dépasser.
        $taillemax=150;
        // On récupère les dimension initiales de l'image.
        $img = getimagesize($source);
        $x=$img[0];
        $y=$img[1];
        $xori=$x;
        $yori=$y;
        // "Redimensionnement".
        if ($x > $y && $x > $taillemax) {
          $y=$y*(($taillemax)/$x);
          $x=$taillemax;
        } else if ($y > $x && $y > $taillemax) {
          $x=$x*(($taillemax)/$y);
          $y=$taillemax;
        } else if ($y == $x && $x > $taillemax ) {
          $x=$taillemax;
          $y=$taillemax;
        }
        // On peut afficher l'image.
        ?>
        <a href="image.php?source=<?=$source?>&x=<?=$xori?>&y=<?=$yori?>"><img src="<?=$source?>" alt="" border="0" width="<?=$x?>" height="<?=$y?>"></a>
        taille originale : <?=$xori?>x<?=$yori?><br/>
        <?
      }
    }
  }
?>
Then the image page contains the full size image and a link back to the index page.
<div align="center">
<br>
<?php
echo $_GET["source"], " ", $_GET["x"], " ", $_GET["y"];
$img = $_GET["source"];
$x=$_GET["x"];
$y=$_GET["y"];
?>
<br>
<img src="<?=$img?>" alt="" width="<?=$x?>" height="<?=$y?>">
<br>
<br>
<a href="index.php"><b>Retour</b></a>
</div>