Bildergalerie mit maxWidth & maxHight ?

Gesperrt
halousi
Beiträge: 111
Registriert: Mi 30. Mär 2005, 15:31
Kontaktdaten:

Bildergalerie mit maxWidth & maxHight ?

Beitrag von halousi »

hallo zusammen,
benutze folgende bildergalerie:

Code: Alles auswählen

/*********************************************** 
* CONTENIDO MODUL - INPUT 
* 
* Modulname   :       w3concepts.gallery.v1 
* Author      :     Andreas Kummer 
* Copyright   :     mumprecht & kummer w3concepts 
* Created     :     30-08-2004 
* Modified    :     30-08-2004 
************************************************/ 

class pfad { 

   function pfad($pfad) { 
      $this->pfad = $pfad; 
      $this->pathlen = strlen($this->pfad); 
   } 

   function getPath($root,$level = 0) { 
      $content = $this->readDir($root); 

      foreach ($content as $file) { 
         if (is_dir($root.$file)) { 
            $verzeichnis = substr($root,$this->pathlen); 
            $returnvalue["{$verzeichnis}{$file}/"] = str_repeat(" ",$level * 5).$file; 
            $returnvalue = array_merge($returnvalue,$this->getPath($root.$file."/",$level+1)); 
         } 
      } 

      return $returnvalue; 
   } 

   function readDir($path) { 
      $handle = opendir($path); 

      while ($file = readdir ($handle)) { 
         if ($file != "." && $file != "..") $returnvalue[] = $file; 
      } 
      closedir($handle); 

      return $returnvalue; 
   } 

   function makeSelect($preselection) { 
      $pfad = $this->getPath($this->pfad); 

      foreach ($pfad as $key => $value) { 
         if ($preselection == $key) { 
            echo "<option value=\"$key\" selected=\"selected\">$value</option>"; 
         } else { 
            echo "<option value=\"$key\">$value</option>"; 
         } 
      } 
   } 
} 

$pfad = new pfad($cfgClient[$client]['path']['frontend'].$cfgClient[$client]['upload']); 

echo "<table cellspacing=\"0\" cellpadding=\"10\" border=\"0\">"; 

echo "<tr><td>Bilderpfad:</td>"; 
echo "<td><select size=\"1\" name=\"CMS_VAR[0]\" />"; 
$pfad->makeSelect("CMS_VALUE[0]"); 
echo "</td></tr>"; 

echo "<tr><td>Thumbnailpfad:</td>"; 
echo "<td><select size=\"1\" name=\"CMS_VAR[1]\" />"; 
$pfad->makeSelect("CMS_VALUE[1]"); 
echo "</td></tr>"; 

echo "<tr><td>Thumbnailbreite (Max.):</td>"; 
echo "<td><input type=\"text\" name=\"CMS_VAR[2]\" value=\"CMS_VALUE[2]\" size=\"5\" /></td></tr>"; 

echo "<tr><td>Thumbnailhöhe (Max.):</td>"; 
echo "<td><input type=\"text\" name=\"CMS_VAR[3]\" value=\"CMS_VALUE[3]\" size=\"5\" /></td></tr>"; 

echo "<tr><td>Anzahl Spalten:</td>"; 
echo "<td><input type=\"text\" name=\"CMS_VAR[4]\" value=\"CMS_VALUE[4]\" size=\"5\" /></td></tr>"; 

echo "<tr><td>Anzahl Zeilen:</td>"; 
echo "<td><input type=\"text\" name=\"CMS_VAR[5]\" value=\"CMS_VALUE[5]\" size=\"5\" /></td></tr>"; 

echo "<tr><td>Text für Previous-Link:</td>"; 
echo "<td><input type=\"text\" name=\"CMS_VAR[6]\" value=\"CMS_VALUE[6]\" size=\"15\" /></td></tr>"; 

echo "<tr><td>Text für Next-Link:</td>"; 
echo "<td><input type=\"text\" name=\"CMS_VAR[7]\" value=\"CMS_VALUE[7]\" size=\"15\" /></td></tr>"; 

echo "<tr><td>Text für Übersicht-Link:</td>"; 
echo "<td><input type=\"text\" name=\"CMS_VAR[8]\" value=\"CMS_VALUE[8]\" size=\"15\" /></td></tr>"; 

echo "<tr><td>Anzahl der Zeichen für den Kurztext:</td>"; 
echo "<td><input type=\"text\" name=\"CMS_VAR[9]\" value=\"CMS_VALUE[9]\" size=\"15\" /></td></tr>"; 

echo "</table>"; 
und

Code: Alles auswählen


<? 
/*********************************************** 
* CONTENIDO MODUL - OUTPUT 
* ORDER BY e.title ASC
* Modulname   :       w3concepts.gallery.v1 
* Author      :     Andreas Kummer 
* Copyright   :     mumprecht & kummer w3concepts 
* Created     :     30-08-2004 
* Modified    :     30-08-2004 
************************************************/ 

class gallery { 

   function gallery() { 
      // initialwerte setzen 
      $this->setInitValues(); 

      // aussteigen, falls initialwerte nicht sinnvoll 
      if (!$this->checkInitValues()) return false; 

      // quellverzeichnis auslesen 
      $this->readDir();

      // zeiger für showNextPicture setzen 
      if (empty($_REQUEST['pos'])) { 
         $this->showNextPictureSeq = -1; 
      } else { 
         $this->showNextPictureSeq = $_REQUEST['pos'] - 1; 
      } 

      // datenbankzugriff initialisieren 
      $this->db = new DB_Contenido; 

      // galerie ausgeben 
      $this->showGallery();

      // gegebenenfalls navigation ausgeben 
      $this->showNavigation();



   } 

   function setInitValues() { 
      // konfigurationswerte aus dem input-script 
      // übernehmen 
      $this->path['pictures'] = "CMS_VALUE[0]"; 
      $this->path['thumbs'] = "CMS_VALUE[1]"; 
      $this->path['upload'] = $GLOBALS['cfgClient']["{$GLOBALS['client']}"]['upload']; 
      $this->path['html'] = $GLOBALS['cfgClient']["{$GLOBALS['client']}"]['path']['htmlpath']; 
         $this->path['client'] = $GLOBALS['client']; 
         $this->path['lang'] = $GLOBALS['lang']; 
         $this->path['idcat'] = $GLOBALS['idcat']; 
         $this->path['idart'] = $GLOBALS['idart']; 
         $this->path['pos'] = $GLOBALS['pos']; 
      $this->abspath['pictures'] = $GLOBALS['cfgClient']["{$GLOBALS['client']}"]['path']['frontend'].$GLOBALS['cfgClient']["{$GLOBALS['client']}"]['upload'].$this->path['pictures']; 
      $this->abspath['thumbs'] = $GLOBALS['cfgClient']["{$GLOBALS['client']}"]['path']['frontend'].$GLOBALS['cfgClient']["{$GLOBALS['client']}"]['upload'].$this->path['thumbs']; 
      $this->htmlpath = $GLOBALS['cfgClient']["{$GLOBALS['client']}"]['path']['htmlpath'].$GLOBALS['cfgClient']["{$GLOBALS['client']}"]['upload']; 
      $this->thumbnailSize['width'] = "CMS_VALUE[2]"; 
      $this->thumbnailSize['height'] = "CMS_VALUE[3]"; 
      $this->tableSize['cols'] = "CMS_VALUE[4]"; 
      $this->tableSize['rows'] = "CMS_VALUE[5]"; 
      $this->link['previous'] = "CMS_VALUE[6]"; 
      $this->link['next'] = "CMS_VALUE[7]"; 
         $this->uebersicht = "CMS_VALUE[8]"; 
         $this->teaser = "CMS_VALUE[9]"; 
   } 

   function checkInitValues() { 
      // prüfen, ob es sich bei den übergebenen pfaden 
      // um tatsächlich vorhandene pfade im dateisystem 
      // handelt. gegebenenfalls wird eine ausgabe 
      // an den browser vorgenommen und false zurückgegeben. 
      if (!chdir($this->abspath['pictures'])) { 
         echo "<p>Das Verzeichnis '{$this->abspath['pictures']}' existiert im Dateisystem 
            des Servers nicht. Entweder müssen Sie es noch anlegen oder die 
            Konfiguration Ihres Modules anpassen.</p>"; 
         return false; 
      } 
      if (!chdir($this->abspath['thumbs'])) { 
         echo "<p>Das Verzeichnis '{$this->abspath['thumbs']}' existiert im Dateisystem 
            des Servers nicht. Entweder müssen Sie es noch anlegen oder die 
            Konfiguration Ihres Modules anpassen.</p>"; 
         return false;          
      } 

      if ($this->thumbnailSize['width'] == '') $this->thumbnailSize['width'] = 100; 
      if ($this->thumbnailSize['height'] == '') $this->thumbnailSize['height'] = 100; 

      if ($this->tableSize['cols'] == '') $this->tableSize['cols'] = 3; 
      if ($this->tableSize['rows'] == '') $this->tableSize['rows'] = 3; 

      if ($this->link['previous'] == '') $this->link['previous'] = '[:: rückwärts ]'; 
      if ($this->link['next'] == '') $this->link['next'] = '[ vorwärts ::]'; 

      if ($this->teaser == '') $this->teaser = '1000'; 

      // rückgabe im erfolgsfall 
      return true; 
   } 

   function readDir() { 
      $dir = opendir($this->abspath['pictures']); 
      while ($file = readdir($dir)) { 
         $bildinfo = @getimagesize($this->abspath['pictures'].$file); 
         if (!empty($bildinfo)) { 
            $picture[] = $file; 
         } 
      }
      
      sort($picture); 
      closedir($dir);

      foreach ($picture as $picture2) { 
         if (!empty($picture2)) $this->picture[] = $picture2; 
      } 
   } 

   function showNextPicture() { 
      // zeiger um eins erhöhen 
      $this->showNextPictureSeq++; 

      // wenn keine bild mehr vorhanden ist, false zurück geben 
      if ($this->showNextPictureSeq >= count($this->picture)) return ''; 

      // thumbnail generieren falls erforderlich 
      $size = $this->generateThumb($this->picture["{$this->showNextPictureSeq}"]); 

      // originalgrösse des bildes ermitteln 
      $originalsize = getimagesize($this->abspath['pictures'].$this->picture["{$this->showNextPictureSeq}"]); 

      // referenz zurück geben 

if ($_REQUEST['galerie']==""||$_REQUEST['galerie']=="klein"){ 

$pos = $this->showNextPictureSeq; 

   return "<a href=\"{$this->path['html']}front_content.php?client={$this->path['client']}&lang={$this->path['lang']}&idcat={$this->path['idcat']}&idart={$this->path['idart']}&pos=".$pos."&galerie=gross\"><img src=\"{$this->htmlpath}{$size['filename']}\" width=\"{$size['width']}\" height=\"{$size['height']}\" border=\"1\"/></a>"; 
} 

if ($_REQUEST['galerie']=="gross"){ 
   return "<img class=\"line\" src=\"{$this->path['upload']}{$this->path['pictures']}{$this->picture["{$this->showNextPictureSeq}"]}\" border=\"1\" bordercolor=\"#ff6600\" width=\"550\" max-height=\"415px\"/>"; 
} 

   } 

function generateThumb($filename) { 

      $src_image_size = getimagesize($this->abspath['pictures'].$filename); 

      // prüfen, ob thumbnail bereits vorhanden ist 
      if (!file_exists("{$this->abspath['thumbs']}{$this->thumbnailSize['width']}.{$this->thumbnailSize['height']}.$filename.jpg")) { 

         // ermitteln ob das bild auf bestimmte höhe oder bestimmte breite zu reduzieren ist 
         // sowie ermitteln, um welchen faktor das bild zu verkleinern ist 
         if ($src_image_size[0]/$src_image_size[1] > $this->thumbnailSize['width']/$this->thumbnailSize['height']) { 
            $verkleinerungsfaktor = $this->thumbnailSize['width']/$src_image_size[0]; 
         } else { 
            $verkleinerungsfaktor = $this->thumbnailSize['height']/$src_image_size[1]; 
         } 

         // berechnen der thumbnailgrösse 
         $bildhoehe = round($src_image_size[1] * $verkleinerungsfaktor); 
         $bildbreite = round($src_image_size[0] * $verkleinerungsfaktor); 

         // thumbnail erstellen 
         $dst_im = imagecreatetruecolor($bildbreite,$bildhoehe); 
         if ($src_image_size[2] == 1) { 
            $src_im = imagecreatefromGIF("{$this->abspath['pictures']}$filename"); 
         } elseif ($src_image_size[2] == 2) { 
            $src_im = @ImageCreateFromJPEG("{$this->abspath['pictures']}$filename"); 
         } else { 
            $src_im = @imagecreatefromgd("{$this->abspath['pictures']}$filename"); 
         } 
         imagecopyresampled ($dst_im,$src_im,0,0,0,0,$bildbreite,$bildhoehe,$src_image_size[0],$src_image_size[1]); 
         imagejpeg ($dst_im,"{$this->abspath['thumbs']}{$this->thumbnailSize['width']}.{$this->thumbnailSize['height']}.$filename.jpg",100); 
          
         $size['width'] = $bildbreite; 
         $size['height'] = $bildhoehe; 
      } else { 
         $thumbnailsize = getimagesize("{$this->abspath['thumbs']}{$this->thumbnailSize['width']}.{$this->thumbnailSize['height']}.$filename.jpg"); 
         $size['width'] = $thumbnailsize[0]; 
         $size['height'] = $thumbnailsize[1]; 
      } 

      $size['filename'] = "{$this->path['thumbs']}{$this->thumbnailSize['width']}.{$this->thumbnailSize['height']}.$filename.jpg"; 
    
      return $size; 
   } 

   function getDescription() { 
        
      $sql = "SELECT description FROM {$GLOBALS['cfg']['tab']['upl']} 
         WHERE 
            filename = '{$this->picture[$this->showNextPictureSeq]}' 
            AND dirname = '{$this->path['pictures']}' 
         "; 

      $this->db->query($sql); 
      $this->db->next_record(); 

      return $this->db->f("description");; 
   } 

function showGallery() { 

if ($_REQUEST['galerie']=="gross"){ 


      echo "<table width=\"100%\" height=\"300\">\n"; 
      echo "<tr>\n";          
      echo "<td align=\"center\" width=\"$cellwidth%\">\n".$this->showNextPicture()."\n</td>\n"; 
      echo "</tr>\n"; 
$beschreibung = $this->getDescription(); 
      echo "<tr>\n"; 
      echo "<td align=\"center\" width=\"$cellwidth%\" class=\"Normal\">\n{$beschreibung}\n</td>\n"; 
      echo "</tr>\n"; 
      echo "</table>\n"; 


} else { 

      $cellwidth = floor(100/$this->tableSize['cols']); 
      echo "<table width=\"100%\">\n"; 
      for ($i = 0;$i < $this->tableSize['rows'];$i++) { 
         $beschreibung = null; 

         echo "<tr>\n";          
         for ($j = 0;$j < $this->tableSize['cols'];$j++) { 
            echo "<td align=\"center\" width=\"$cellwidth%\">\n".$this->showNextPicture()."\n</td>\n"; 
            $beschreibung[] = substr($this->getDescription(),0,$this->teaser); 
         } 
         echo "</tr>\n"; 

         echo "<tr>\n"; 
         for ($j = 0;$j < $this->tableSize['cols'];$j++) { 
                   if ($beschreibung[$j]!=""){ 
                     $beschreibung[$j]=$beschreibung[$j]." ..."; 
                  } 
            echo "<td align=\"center\" width=\"$cellwidth%\" class=\"Normal\">\n{$beschreibung[$j]}\n</td>\n"; 
         } 
         echo "</tr>\n"; 
      } 
      echo "</table>\n"; 
   } 
} 

   function showNavigation() { 

      if ($this->tableSize['cols'] * $this->tableSize['rows'] < count($this->picture)) { 
         echo "<table align=\"center\" width=\"400\">\n<tr>\n"; 

         if (!empty($_REQUEST['pos'])) { 
            $pos = ($this->showNextPictureSeq <= $this->tableSize['cols'] * $this->tableSize['rows']) ? (0) : ($this->showNextPictureSeq - (2 * $this->tableSize['cols'] * $this->tableSize['rows']) + 1); 
            $pos = ($pos < 0) ? (0) : ($pos); 
                  if ($_REQUEST['galerie']=="gross"){ 
                     $pos=$_REQUEST['pos']-1; 
                  } 
            $link = $GLOBALS['sess']->url("front_content.php?client={$GLOBALS['client']}&lang={$GLOBALS['lang']}&idcat={$GLOBALS['idcat']}&idart={$GLOBALS['idart']}&pos=$pos&galerie={$_REQUEST['galerie']}"); 
            echo "<td style=\"text-align:left; width:33%\"><a href=\"$link\">{$this->link['previous']}</a></td>"; 
         } else { 
            echo "<td style=\"text-align:left; width:33%\">&nbsp;</td>"; 
         } 

             if ($_REQUEST['galerie']=="gross"){ 
             $pos = $_REQUEST['pos']/$this->tableSize['cols']/$this->tableSize['rows']; 
             $pos = substr($pos,0,strpos($pos,".")); 
             if ($pos!="0"){ 
                $pos = $pos*$this->tableSize['cols']*$this->tableSize['rows']; 
             } 
         echo "<td style=\"text-align:center; width:33%\">                   
                  <a href=\"{$this->path['html']}front_content.php?client={$this->path['client']}&lang={$this->path['lang']}&idcat={$this->path['idcat']}&idart={$this->path['idart']}&pos=".$pos."&galerie=klein\">$this->uebersicht</a> 
                     </td>"; 
               } else { 
               echo "<td style=\"text-align:center; width:33%\">&nbsp;</td>"; 
               } 

         if ($this->showNextPictureSeq + 1 < count($this->picture)) { 
            $pos = $this->showNextPictureSeq + 1; 
            $link = $GLOBALS['sess']->url("front_content.php?client={$GLOBALS['client']}&lang={$GLOBALS['lang']}&idcat={$GLOBALS['idcat']}&idart={$GLOBALS['idart']}&pos=$pos&galerie={$_REQUEST['galerie']}"); 
           echo "<td style=\"text-align:right; width:33%\"><a href=\"$link\">{$this->link['next']}</a></td>"; 


         } else { 
            echo "<td style=\"text-align:right; width:33%\">&nbsp;</td>"; 
         } 

         echo "</tr>\n</table>\n"; 
      } 
   } 

} 

$gallery = new gallery(); 
?>
habe mir die ausgabe so angepasst, daß die bilder im gleichen fenster mit einer breite von 550px ausgegeben weden. das problem sind die hochformat-bilder. diese sollen eigentlich nur mit einer höhe von 550px ausgegeben werden. habe es schon mit css2-befehlen "maxwidth" und "maxhight" versucht, leider ohne erfolg.
hat vieleicht jemand eine idee wie ich das problem lösen könnte?


viele grüße
hannes
emergence
Beiträge: 10653
Registriert: Mo 28. Jul 2003, 12:49
Wohnort: Austria
Kontaktdaten:

Beitrag von emergence »

sieh dir mal die css eigenschaften clip mit overflow:hidden; an.
*** make your own tools (wishlist :: thx)
kummer
Beiträge: 2423
Registriert: Do 6. Mai 2004, 09:17
Wohnort: Bern, Schweiz
Kontaktdaten:

Beitrag von kummer »

schau dir das mal an:

http://olaf-bosch.de/bugs/scalieren.html

gruss,
andreas
aitsu.org :: schnell - flexibel - komfortabel :: Version 2.2.0 (since June 22, 2011) (jetzt mit dual license GPL/kommerziell)
Gesperrt