/**
* Gallery Snippet
* ________________________________________
*
*
* @author Roland Schär
* @date 2006-02-19
*/
$basefolder = '/assets/gallery/';
$maxwidth = isset($maxsize) ? $maxsize : 120;
$imgRoot = $_SERVER['DOCUMENT_ROOT'] . $basefolder;
if( isset($_GET['image']) && isset($_GET ['gallery']) ) {
$images = getImages($imgRoot . $_GET['gallery']);
$pos = array_search($_GET['image'],$images);
$overview .= '<p><a href="'.$_SERVER['SCRIPT_NAME'].'?id='.$modx->documentIdentifier.'&gallery='.$_GET['gallery'].'"><< zurück zur Galerie</a></p><div>';
if($pos>0)
$overview .= '<p style="float:left;width:50%;text-align:left;"><a href="'.$_SERVER['SCRIPT_NAME'].'?id='.$modx->documentIdentifier.'&gallery='.$_GET['gallery'].'&image='.$images[$pos-1].'">vorheriges Bild</a></p>';
if($pos<count($images)-1)
$overview .= '<p style="float:right; width:50%;text-align:right;"><a href="'.$_SERVER['SCRIPT_NAME'].'?id='.$modx->documentIdentifier.'&gallery='.$_GET['gallery'].'&image='.$images[$pos+1].'">nächstes Bild</a></p>';
$overview .= '</div>';
$overview .= '<div class="galleryImageLarge"><img src="assets/gallery/thumb.php?pic=' . $_GET['gallery'] . '/' . $_GET['image'] . '&width=450" alt="" /></div>';
}else if(isset($_GET['gallery'])){
$overview = '<p><a href="'.$_SERVER['SCRIPT_NAME'].'?id='.$modx->documentIdentifier.'"><< zurück zur Übersicht</a></p>';
$images = getImages($imgRoot . $_GET['gallery']);
for($i=0; $i<count($images); $i++){
$overview .= '<div class="galleryImg"><a href="'.$_SERVER['SCRIPT_NAME'].'?id='.$modx->documentIdentifier.'&gallery='.$_GET['gallery'].'&image='.$images[$i].'"><img src="assets/gallery/thumb.php?pic=' . $_GET['gallery'] . '/' . $images[$i] . '&width='.$maxwidth.'" border="0" alt="" /></a></div>';
}
}else{
$galleries = getGalleries($imgRoot);
for($i=0; $i<count($galleries); $i++){
$previewImage = getPreviewImage($imgRoot . $galleries[$i]);
if($previewImage != '') {
$img = '<img src="assets/gallery/thumb.php?pic=' . $galleries[$i] . '/' . $previewImage . '&width=120" alt="" border="0" />';
}else{
$img = '';
}
$overview .= '<div class="gallery"><a href="'.$_SERVER['SCRIPT_NAME'].'?id='.$modx->documentIdentifier.'&gallery='.$galleries[$i].'">' . $img . $galleries[$i].'</a></div>';
}
}
return $overview;
/** **/
function getGalleries($fld){
$arrTopics = array();
$i = 0;
$dir = opendir($fld);
while( $file = readdir($dir) ){
if( $file != "." && $file != ".." ){
if( is_dir($fld."/".$file) ){
$arrTopics[$i] = $file;
$i++;
}
}
}
return $arrTopics;
}
function getImages($fld){
if( file_exists($fld) ){
$imgPath = opendir( $fld );
$i = 0;
while($imgFile = readdir($imgPath)){
if( is_file($fld."/".$imgFile) ){
$arrFiles[$i] = $imgFile;
$i++;
}
}
}
return $arrFiles;
}
function getPreviewImage($fld){
$arrFiles = array();
if( file_exists($fld) ){
$imgPath = opendir( $fld );
$i = 0;
while($imgFile = readdir($imgPath)){
if( is_file($fld."/".$imgFile) ){
$arrFiles[$i] = $imgFile;
$i++;
}
}
}
if( !in_array('titelbild.jpg',$arrFiles) ){
return $arrFiles[0];
}elseif( count($arrFiles) == 0 ){
return '';
}
return 'titelbild.jpg';
}
<?php
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $timestamp).' GMT');
header("Content-type: image/jpeg");
header('Content-transfer-encoding: binary');
$im=imagecreatefromjpeg($pic);
$orange=imagecolorallocate($im, 220, 210, 60);
$px=(imagesx($im) - 7.5 * strlen($string)) / 2;
$old_x=imageSX($im);
$old_y=imageSY($im);
$new_w=(int)($width);
if (($new_w<=0) or ($new_w>$old_x)) {
$new_w=$old_x;
}
$new_h=($old_x*($new_w/$old_x));
if ($old_x > $old_y) {
$thumb_w=$new_w;
$thumb_h=$old_y*($new_h/$old_x);
}
if ($old_x < $old_y) {
$thumb_w=$old_x*($new_w/$old_y);
$thumb_h=$new_h;
}
if ($old_x == $old_y) {
$thumb_w=$new_w;
$thumb_h=$new_h;
}
$thumb=ImageCreateTrueColor($thumb_w,$thumb_h);
imagecopyresized($thumb,$im,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
imagejpeg($thumb,"",90);
imagedestroy($thumb);
?>