PHPAY -> Optimisation d'un script de gallerie

Statut
N'est pas ouverte pour d'autres réponses.

aKC1a

OldSchool CS Star
Bjour ,

voila un petit script qui permet d'afficher les img d'un repertoire dans une page web a 150px et de les linkée avec les img réelle taille

Code:
<? 
$dossier = opendir("photos/"); 
$i=0; 
$temp=1; 

while ($Fichier = readdir($dossier)) 
{ 

if ( $Fichier != ".." && $Fichier != "." && $Fichier != "" ) 
{ 

if ( $temp == 1 ) { echo '<tr>'; } 

echo '<td> 
<a href="photos/'.$Fichier.'"><img src="photos/'.$Fichier.'" border=0 width="150px" alt="'.$Fichier.'"></a><br><span align=left>'.$Fichier.'</span> 
</td>'; 

if ( $temp == 3 ) { echo '</tr>'; $temp = 0 ;} 

$temp++; 
} 
} 

closedir($dossier); 

?>
Comme vous pouvez les voir, il affiche également sous l'image son nom.
Ce que je voudrais c''est qu'il affiche le nom mais sans l'extension de fichier.
Merci d'avance. ;)
 

Jereck

Α & Ω
Staff
Tu peux toujours faire split($fichier, '.'); et ne pas ré-afficher la dernière variable renvoyée.
 

null

ose();
Moi je t'invite à utiliser la fonction glob() pour prendre tes images.

Une dernière chose, je te conseille d'utiliser la création de minatures, comme j'utilise sur www.revoxweb.com ou www.veda.be car pour les connexions bas débit, il télécharge les images puis les redimensionne :

tu as les images normales et à l'appel du script, il vérifie que pour chaque image, il existe une miniature qui a pour nom : @nom_de_l_image.jpg, sinon il créé une minature

Code:
<?php
function imageresize($img,$target="",$width=0,$height=0,$percent=0)
{
    if(strpos($img,".jpg") !== false or strpos($img,".jpeg") !== false)
    {
       $image = ImageCreateFromJpeg($img);
       $extension = ".jpg";
    }
    elseif(strpos($img,".png") !== false)
    {
       $image = ImageCreateFromPng($img);
       $extension = ".png";
    }
    elseif(strpos($img,".gif") !== false)
    {
       $image = ImageCreateFromGif($img);
       $extension = ".gif";
    }

    $size = getimagesize ($img);

    if($width and !$height)
       $height = ($size[1] / $size[0]) * $width;
    elseif(!$width and $height)
       $width = ($size[0] / $size[1]) * $height;
    elseif($percent)
    {
       $width = $size[0] / 100 * $percent;
       $height = $size[1] / 100 * $percent;
    }
    elseif(!$width and !$height and !$percent)
    {
       $width = 100;
       $height = ($size[1] / $size[0]) * $width;
    }

    $thumb = imagecreatetruecolor ($width, $height);

    if(function_exists("imageCopyResampled"))
    {
       if(!@ImageCopyResampled($thumb, $image, 0, 0, 0, 0, $width, $height, $size[0], $size[1]))
          ImageCopyResized($thumb, $image, 0, 0, 0, 0, $width, $height, $size[0], $size[1]);
    }
    else
       ImageCopyResized($thumb, $image, 0, 0, 0, 0, $width, $height, $size[0], $size[1]);

    if(!$target)
      $target = "temp".$extension;

    $return = true;

    switch ($extension)
    {
        case ".jpg":
          imagejpeg($thumb, $target, 70);
        break;
        case ".gif":
          imagegif($thumb, $target);
        break;
        case ".png":
          imagepng($thumb, $target);
        break;
        default:
          $return = false;
    }

    return $return;
} //fin imageresize()

// ta boucle
if(!file_exists($dir."/@".$file))
{
     list($width, $height, $type, $attr) = getimagesize($dir."/".$file);
     $width = ($width/$height)*73;
     imageresize($dir."/".$file, $dir."/@".$file, $width, 73, 0);
}
// la fin de ta boucle

?>
 
Statut
N'est pas ouverte pour d'autres réponses.
Haut