* @copyright Robert Weiler * @license GPL */ function println($text, $newline = "\r\n") { print $text . $newline; } // Variablen holen if (phpversion() < '4.1.0') { global $HTTP_SERVER_VARS, $HTTP_GET_VARS; // intern benötigte Variablen $PHP_SELF = $HTTP_SERVER_VARS['PHP_SELF']; // Generelle Konfiguration $action = $HTTP_GET_VARS['action']; $path = $HTTP_GET_VARS['path']; $pprow = $HTTP_GET_VARS['pprow']; // Farbkonfiguration $bgcolor = $HTTP_GET_VARS['bgcolor']; $text = $HTTP_GET_VARS['text']; $link = $HTTP_GET_VARS['link']; $alink = $HTTP_GET_VARS['alink']; $vlink = $HTTP_GET_VARS['vlink']; } else { // intern benötigte Variablen $PHP_SELF = $_SERVER['PHP_SELF']; // Generelle Konfiguration $action = $_REQUEST['action']; $path = $_REQUEST['path']; $pprow = $_REQUEST['pprow']; // Farbkonfiguration $bgcolor = $_REQUEST['bgcolor']; $text = $_REQUEST['text']; $link = $_REQUEST['link']; $alink = $_REQUEST['alink']; $vlink = $_REQUEST['vlink']; } // undefinierte Variablen auf Standardwerte setzen if (empty($action)) $action = 'gal'; if (empty($path)) $path = '.'; if (empty($pprow)) $pprow = 4; if (empty($bgcolor)) $bgcolor = '#cccccc'; if (empty($text)) $text = '#000000'; if (empty($link)) $link = '#0000ff'; if (empty($alink)) $alink = '#ff0000'; if (empty($vlink)) $vlink = '#990099'; switch ($action) { // eine Galerie soll erzeugt werden case 'gal': // Versuchen das Verzeichnis zu öffnen if (($dir = @opendir($path)) != false) { $pics = array(); // Verzeichnis auslesen, JPEGs und PNGs zum Bildarray hinzufügen while ($file = readdir($dir)) { if (preg_match('/.+?\.(jpeg|jpg|png)$/i', $file)) $pics[] = $file; } closedir($dir); // die Variable $path muss am Ende einen Slash haben if (!preg_match('#/$#', $path)) $path .= '/'; if (count($pics) > 0) { // das Bildarray sortieren sort($pics); // Output-Buffering samt Kompression aktivieren falls verfügbar if (function_exists('ob_start') && function_exists('ob_gzhandler')) ob_start('ob_gzhandler'); // HTML-Ausgabe beginnen, die Seite bleibt für einen Tag gültig header('Content-Type: text/html; charset=UTF-8'); header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 86400) . ' GMT'); println(''); println(''); println(''); println(''); println('Galerie'); println(''); println(''); println(''); println(''); println('

Galerie

'); println(''); // Zählvariable initialisieren $i = 0; // Spaltenbreite berechnen $td_width = (int)(100 / $pprow); // jedes einzelne Bild in die Übersicht aufnehmen foreach ($pics as $pic) { if ($i <= 0) println(''); $i++; $pic_size = getimagesize($path . $pic); $thumb_w = (int)($pic_size[0] / 5); $thumb_h = (int)($pic_size[1] / 5); println(''); if ($i >= $pprow) { println(''); $i = 0; } } // die Tabelle ordentlich abschließen if ($i != 0) { while ($i != 0) { println(''); $i++; if ($i >= $pprow) $i = 0; } println(''); } // die HTML-Ausgabe ordentlich abschließen println('
Thumbnail: ' . $pic . '
' . $pic . '
 
'); println(''); println(''); } else { header('Content-Type: text/plain; charset=UTF-8'); print 'In dem Verzeichnis "' . $path . '" liegen keine unterstützten Bilder (JPEG, JPG, PNG).'; } } else { header('Content-Type: text/plain; charset=UTF-8'); print 'Das Verzeichnis "' . $path . '" konnte nicht zum lesen geöffnet werden.'; } break; // ein Thumbnail soll ausgegeben werden case 'thumb': // Typ bestimmen - JPEG oder PNG if (file_exists($path)) { if (preg_match('/.+?\.jp(eg|g)$/i', $path)) $type = 'jpeg'; elseif (preg_match('/.+?\.png$/i', $path)) $type = 'png'; } $orig = false; // Originalbild öffnen if ($type == 'jpeg') $orig = @imagecreatefromjpeg($path); elseif ($type == 'png') $orig = @imagecreatefrompng($path); if ($orig) { $orig_w = imagesx($orig); $orig_h = imagesy($orig); $thumb_w = (int)($orig_w / 5); $thumb_h = (int)($orig_h / 5); $thumb = imagecreatetruecolor($thumb_w, $thumb_h); // Thumbnail vorbereiten imagecopyresized($thumb, $orig, 0, 0, 0, 0, $thumb_w, $thumb_h, $orig_w, $orig_h); // das Thumbnail bleibt für 10 Tage gültig header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 864000) . ' GMT'); // das Thumbnail direkt zur Standardausgabe (Browser) ausgeben if ($type == 'jpeg') { header('Content-Type: image/jpeg'); imagejpeg($thumb, '', 30); } elseif ($type == 'png') { header('Content-Type: image/png'); imagepng($thumb); } } else { // ein Bild mit einer Fehlermeldung erzeugen $im = imagecreate(88, 31); $bc = imagecolorallocate($im, 0, 0, 0); $bgc = imagecolorallocate($im, 255, 255, 255); $tc = imagecolorallocate($im, 0, 0, 0); imagefilledrectangle($im, 0, 0, 88, 31, $bc); imagefilledrectangle($im, 1, 1, 86, 29, $bgc); imagestring($im, 3, 20, 8, '-error-', $tc); // das Bild als PNG ausgeben, bleibt für fünf Minuten gültig header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 300) . ' GMT'); header('Content-Type: image/png'); imagepng($im); } break; default: header('Content-Type: text/plain; charset=UTF-8'); print 'Es wurde keine gültige Aktion angegeben.'; } ?>