Jump to content
php.lv forumi

bilzu galerija


RaitisRR

Recommended Posts

Kaut kur agrāk šo dabūju, izmantojot kā paraugu, uztaisīju savu galeriju.

Galerija

<?php

$thumb = "images";   // Thumbiņu direkcija
$thumbwidth = 160;   // Thumbiņa horizontālais izmērs
$imagequality = 100; // Thumbiņa kvalitāte %
$cols = 4;           // Kolumiņas
$startrow=1;                    //rinda no kuras saak raadiit
$rowcount=3;                        //rindu skaits
$filelist = false;    // Rādīt failu sarakstu    [true/false]
$bildiic = true;     // Rādīt bildīšu thumbiņus [true/false]

if ($filelist){
$dir = opendir("./");
while (($g = readdir($dir)) !== false) {
if (($g != ".")&&($g != "..")&&($g != "index.php")&&($g != $thumb)){
?>
<a href="<?php echo $g; ?>"><?php echo $g; ?></a><br />
<?php }; }; closedir($dir); }; ?>
<?php
if ($bildiic){
$files = array();
if ($handle = opendir('.')) {
 while (false !== ($file = readdir($handle))) {
     if ($file != "." && $file != "..") {
         if (eregi("\.jpe?g$", $file) ||
          eregi("\.gif$", $file) ||
          eregi("\.png$", $file)) {
          $files[] = $file;
      }
     }
 }
 closedir($handle);
}
sort($files);

if (!is_dir($thumb)) {
mkdir($thumb, 0755);
}

$i = 0;
$th = array();
$iw = array();
$ih = array();
$ifs = array();
foreach ($files as $image) {
     $thumbimage = $thumb."/".$image;
     $thumb_exists = file_exists($thumbimage);
     $size = GetImageSize($image);
     $width  = $size[0];
     $height = $size[1];
     $type   = $size[2];
     if (!$thumb_exists) {
         set_time_limit(30);
         switch ($type) {
             case 1 :
             $im = ImageCreateFromGIF($image);
              break;
             case 2 :
             $im = ImageCreateFromJPEG($image);
             break;
             case 3 :
             $im = ImageCreateFromPNG($image);
             break;
         }

         $newwidth = $thumbwidth;
         $newheight = ($newwidth / $width) * $height;

         $im2 = ImageCreateTrueColor($newwidth,$newheight);
         ImageCopyResampled($im2,$im,0,0,0,0,$newwidth,$newheight,$width,$height);
         switch ($type) {
             case 1:
             ImageGIF($im2, $thumbimage);
             break;
             case 2:
             ImageJpeg($im2, $thumbimage, $imagequality);
             break;
             case 3:
             ImagePNG($im2, $thumbimage);
             break;
             imagedestroy($im);
             imagedestroy($im2);
         }

     }
$th[$i] = $thumbimage;
$iw[$i] = $width;
$ih[$i] = $height;
$ifs[$i] = filesize($image);
$i++;
}

echo "<table border=\"1\" align=\"center\">";


 $rows = round(count($th)/$cols);
 if (($rows * $cols) < (count($th))) {
     $rows++;
 }
 for ($i = $startrow; $i <= $startrow+$rowcount-1; $i++) {
     echo "<tr>";
     for ($j = 1; $j <= $cols; $j++) {
         $td = (($i - 1) * $cols) + $j;
         $iu = ($td - 1);
         if (isset($th[$iu])) {
             $op = "";
             $op .= "<td>\n<div align=\"center\">\n<br>\n";
             $op .= "<a onClick=\"window.open('$files[$iu]','_blank','toolbar=no,
                              location=no,directories=no,status=no,menubar=no,
                              scrollbars=no,width=800,height=600')\">\n";
             $op .= "<img src=\"$th[$iu]\" border=\"0\">\n";
             $op .= "<br>$iw[$iu] x $ih[$iu]\n";
             $op .= "<br>$ifs[$iu] B.</a>\n";
             $op .= "<br>\n</div>\n</td>\n";
             echo $op;
         } else {
             echo "<td>\n<br></td>\n";
         }
     }
     echo "</tr>\n";
 }
echo "</table>";
};
?> 

Edited by apophis
Link to comment
Share on other sites

×
×
  • Create New...