We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32495
    • 3 Posts
    Hi,

    I made a simple gallery-script for phpwcms.
    After some small changes, it`s working well with ModX.
    Here is an example: http://www.surfclub-bernau.de

    // SimpleGallery - a simple gallery-script for ModX
    // gdlib 2 is required for generating thumbnails
    // put your images in a folder, thumbnails will be generated by the script
    // the folder must be writable - chmod the folder to 777
    // if you call your gallery with '&generatethumbs' at the end of your path, all thumbnails will be generated new
    // if you call your gallery with '&deletethumbs' at the end of your path, all thumbnails will be deleted
    // Andi Platen, 05.08.2006, www.wireframe.de|www.gleitschirm-taxi.de|www.mountain-panorama.com
    
    // ------- edit the parameters to your needs -------------------------- //
    
    $backButton = 'back';
    $dirName = 'assets/images/gallery'; // path to your gallery images
    $noImage = 'assets/images/no_image.jpg'; // path to your empty-image
    $spaceImage = 'assets/images/img_blank.gif'; // path to an empty spacer-gif
    $border_style = 'border:solid 1px #666666'; // style of image borders
    $thumbWidth = 120; // thumbnail width
    $thumbHeight = 60; // thumbnail height
    $imageSpaceH = 10; // horizontal space between images
    $imageSpaceV = 10; // vertical space between images
    $imageColumn = 5; // number of columns
    $thumb_quality = 90;
    
    // ------- end edit --------------------------------------------------- //
    
    $form_action = explode('&', $_SERVER['QUERY_STRING']);
    $form_action = $form_action[0];
    $form_action = 'index.php?' . $form_action;
    
    
    if(isset($_REQUEST['big']))
    {
    	$show_big = $dirName . '/' . $_REQUEST['big'] . '.jpg';
    	$big_size = getimagesize($show_big);
    
    	echo '<table border="0" cellspacing="0" cellpadding="0">
    	<tr>
    		<td style="' . $border_style . '"><a href="' . $form_action . '" title="' . $backButton . '"><img src="' . $show_big . '" ' . $big_size[3] . ' border="0" alt="' . $_REQUEST['big'] . '"></a></td>
    	</tr>
    	<tr>
    		<td>[ <a href="' . $form_action . '" title="' . $backButton . '">' . $backButton . '</a> ]</td>
    	</tr>
    	</table>';
    }
    else
    {
    	$thumbs = array();
    	$bigs = array();
    
    	$dirList = opendir($dirName);
    	while($file_big = readdir($dirList))
    	{
    		if($file_big != '.' && $file_big != '..' && substr($file_big, 0, 5) != 'thumb')
    		{
          		$big_size = getimagesize($dirName . '/' . $file_big);
        		$file_thumb = $file_big;
        		$file_thumb = 'thumb_' . $file_big;
    
        		if(!file_exists($dirName . '/' . $file_thumb) || isset($_REQUEST['generatethumbs']))
        		{
        			$gd_image  = imagecreatefromjpeg($dirName . '/' . $file_big);
        			$new_picture = imagecreatetruecolor($thumbWidth, $thumbHeight);
        			imagecopyresampled($new_picture, $gd_image, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $big_size[0], $big_size[1]);
        			imagejpeg($new_picture, $dirName . '/' . $file_thumb, $thumb_quality);
        		}
    
           	 	array_push($bigs, $dirName . '/' . $file_big);
          	 	array_push($thumbs, $dirName . '/' . $file_thumb);
      	  	}
    
      	  	if(isset($_REQUEST['deletethumbs']) && substr($file_big, 0, 5) == 'thumb')
        	{
        		unlink($dirName . '/' . $file_big);
        	}
    	}
    	closedir($dirList);
    
    	natsort($thumbs);
    	$bigs = array_values($thumbs);
    
    	echo '<table border="0" cellspacing="0" cellpadding="0">';
    
    	$i = 0;
    	while($i < count($thumbs))
    	{
    		echo '<tr>';
    
    		$k = 1;
    		while($k <= $imageColumn)
    		{
    			if($i + $k < 10)
    			{
    				$imageSel = '00' . ($i + $k);
    			}
    			else if ($i + $k < 100)
    			{
    				$imageSel = '0' . ($i + $k);
    			}
    
    			$bild[$k] = $thumbs[$i + $k - 1];
    			$bild_name = str_replace($dirName . '/' . 'thumb_','',$bild[$k]);
    			$bild_name = str_replace('.jpg','',$bild_name);
    			$link[$k] = $form_action . '&big=' . $bild_name;
    
    			if(!$thumbs[$i + $k - 1])
    			{
    				$bild_name = 'empty';
    				$bild[$k] = $noImage;
    				$link[$k] = $form_action;
    			}
    
    			echo '<td style="' . $border_style . '"><a href="' . $link[$k] . '"><img src="' . $bild[$k] . '" width="' . $thumbWidth . '" height="' . $thumbHeight . '" border="0" alt="' . $bild_name . '"></a></td>';
    			if($k < $imageColumn)
    			{
    				echo '<td style="width:' . $imageSpaceH . 'px"> </td>';
    			}
    
    			$k++;
    		}
    
    		echo '</tr>';
    
    		if($i < count($thumbs) - $imageColumn)
    		{
    			echo '<tr>
    				<td colspan="' . ($imageColumn * 2 - 1) . '" style="height:' . $imageSpaceV . 'px"><img src="' . $spaceImage . '" width="1" height="' . $imageSpaceV . '" alt=""></td>
    			</tr>';
    		}
    
    		$i += $imageColumn;
    	}
    
    	echo '</table>';
    }
    


    Grüzli - Andi
      Gleitschirm Taxi - Tandemfliegen im Chiemgau
      www.gleitschirm-taxi.de

      Faszination Berge
      www.mountain-panorama.com