width = 465; //Sizes for larger photos
$fulls_portrait->height = 620;
$thumbs_portrait->width = 150; //Sizes for thumb photos
$thumbs_portrait->height = 200;
$sWATERMARK = ""; //Watermark string to be stamped on the larger images
// set to "" for no watermark.
$iJPEG_QUALITY = 74; //jpg compression quality 1% to 100%.
// 40% seems fine for web. 100% is good, 1% bad.
// -------------------------------------------------------
// Setup page content / layout
// -------------------------------------------------------
$sPAGE_TITLE = 'PIMP Gallery. 2005'; //Page title in browser title bar
$isPAGE_TITLE = 0; //Whether the page title is to be laid up at the top of the page HTML also.
$sSEPARATOR = '.'; //Non alphanumeric character to separate links. Do NOT use a single quote (')
$iCOLUMNS = 3; //How many photo thumbs you want across the gallery page.
$iROWS = 3; //How many rows of photo thumbs you want down each page.
$sCOPYRIGHT = 'PIMP : 2005';
$sAUTHORS = "Dave Gough";
$isXHTML_LOGO = 0; //Whether to display Valid XHTML! logo
// ------------------------------------------------------
// Setup styles for gallery pages
// -------------------------------------------------------
// Style applied to each gallery page
$sStyle = '
'."\n";
// Style applied to Index page - gallery menu
$sStyle_index = '
'."\n";
// --------------------------------------------------------
// Setup output / caching configs
// --------------------------------------------------------
$isDEBUG = false; // Switch this to true to get loads of verbal ;-)
$isREDIRECT = false; // Redirects the index.html page to the latest gallery
$sURL_PIMP = 'http://www.computertorture.com/pimp/';
//---------------------------------------------------------
//
// END USER CONFIGURATION
//
//---------------------------------------------------------
// --------------------------------------------------------
// Pre-process images
// --------------------------------------------------------
if (isset($command)){
if ($command="clear"){
if ($CAN_DELETE){
system ('rm -r "'.$dir_thumbs.'" "'.$dir_fulls.'" *JPG *jpg *html');
echo '
Cleared directoryCleared directory.
';
exit;
}else{
echo 'Authorisation failureYou do not have permission to run the ?command=clear parameter.
If your are admin you need to set $CAN_DELETE=true in the config at the top of index.php.
This causes a security issue if running on a public server (anyone could delete your images).
';
exit;
}
}
}
$sSEPARATOR = htmlentities($sSEPARATOR);
function read_directory($dir_path){
// Reads all the .jpg files in a directory to an array
global $isDEBUG;
$files = array();
$count = 0;
$directory = opendir($dir_path);
while ($file = readdir($directory)){
if (preg_match("/\.jpg$/i",$file)){
$files[$count]->name = $file;
$files[$count]->size = image_size_kb($dir_path.$files[$count]->name);
$sizes = image_size_xy($dir_path.$files[$count]->name);
$files[$count]->width = $sizes["width"];
$files[$count]->height = $sizes["height"];
$files[$count]->geometry = 'square';
if ($sizes["width"] > $sizes["height"]){
$files[$count]->geometry = 'landscape';
}
if ($sizes["width"] < $sizes["height"]){
$files[$count]->geometry = 'portrait';
}
if ($isDEBUG){
echo $files[$count]->name.' ';
echo $files[$count]->width.'w x '.$files[$count]->height.'h ('.$files[$count]->geometry.') ';
echo $files[$count]->size.'Kb
';
}
$count++;
}
}
closedir($directory);
return $files;
}
function image_size_kb($sFile){
// Reads file size of image
clearstatcache();
return floor(filesize($sFile) / 1000);
}
function image_size_xy($sFile){
$img = ImageCreateFromJPEG($sFile);
$info["width"] = ImageSx($img);
$info["height"] = ImageSy($img);
ImageDestroy($img);
return $info;
}
$files = read_directory($dir);
if(!is_dir($dir_thumbs)){
if (!mkdir ($dir_thumbs)){
echo 'Could not create directory '.$dir_thumbs;
exit();
}
$dir_thumbs = $dir.'thumbs/';
}
if(!is_dir($dir_fulls)){
if (!mkdir ($dir_fulls)){
echo 'Could not create directory '.$dir_fulls;
exit();
}
}
foreach ($files as $image){
echo 'The file we have is ' . $image->name;
if (!file_exists($dir_thumbs.$image->name))
{
echo 'Copying file.';
system ('cp "'.$dir.$image->name.'" "'.$dir_thumbs.$image->name . '"');
if ($image->geometry == 'portrait'){
system ('mogrify -resize '.$thumbs_portrait->width.'x'.$thumbs_portrait->height.'! -quality '.$iJPEG_QUALITY.' "'.$dir_thumbs.$image->name .'"');
if ($isDEBUG){echo 'Portrait: mogrify -resize '.$thumbs_portrait->width.'x'.$thumbs_portrait->height.'! -quality '.$iJPEG_QUALITY.' "'.$dir_thumbs.$image->name.'"
';}
}else{
system ('mogrify -resize '.$thumbs_portrait->height.'x'.$thumbs_portrait->width.'! -quality '.$iJPEG_QUALITY.' "'.$dir_thumbs.$image->name . '"');
if ($isDEBUG){echo 'Landscape: mogrify -resize '.$thumbs_portrait->height.'x'.$thumbs_portrait->width.'! -quality '.$iJPEG_QUALITY.' "'.$dir_thumbs.$image->name.'"
';}
}
}
if (!file_exists($dir_fulls.$image->name)){
system ('cp "'.$dir.$image->name.'" "'.$dir_fulls.$image->name . '"');
if ($image->geometry == 'portrait'){
system ('mogrify -resize '.$fulls_portrait->width.'x'.$fulls_portrait->height.'! -quality '.$iJPEG_QUALITY.' "'.$dir_fulls.$image->name . '"');
if ($isDEBUG){echo 'Portrait: mogrify -resize '.$fulls_portrait->width.'x'.$fulls_portrait->height.'! -quality '.$iJPEG_QUALITY.' "'.$dir_fulls.$image->name.'"
';}
}else{
system ('mogrify -resize '.$fulls_portrait->height.'x'.$fulls_portrait->width.'! -quality '.$iJPEG_QUALITY.' "'.$dir_fulls.$image->name .'"');
if ($isDEBUG){echo'Lanscape: mogrify -resize '.$fulls_portrait->height.'x'.$fulls_portrait->width.'! -quality '.$iJPEG_QUALITY.' "'.$dir_fulls.$image->name.'"
';}
}
if(isset($sWATERMARK) && $sWATERMARK!=""){
// Add watermark to larger images if set
$img = ImageCreateFromJPEG($dir_fulls.$image->name);
$black = ImageColorAllocate($img,0,0,0);
$white = ImageColorAllocate($img,0xFF,0xFF,0xFF);
ImageTTFText($img, 26, 0, 20, 40, $black, '/usr/share/enlightenment/E-docs/aircut3.ttf', $sWATERMARK);
ImageJPEG($img , $dir_fulls.$image->name);
ImageDestroy($img);
}
}
}
$iImages_per_page = $iCOLUMNS * $iROWS;
$iPages = ceil(count($files)/$iImages_per_page);
if ($isDEBUG){
echo 'Number of files: ' . count($files);
echo ' Number of images per page: '.$iImages_per_page;
echo ' Number of pages: '.$iPages;
}
$iCell = 0;
for ($iPage = 1; $iPage < $iPages+1; $iPage ++){
// ----------------------------------------------------
// Output the HTML for each gallery page
// ----------------------------------------------------
$sOut = '';
$sOut .= '
'."\n";
$sOut .= ''."\n";
if ($sCOPYRIGHT != ''){
$sOut .= ''."\n";
}
$sOut .= "\n".''."\n";
$sOut .= ''.$sPAGE_TITLE;
if ($iPages > 1){$sOut .= ' '.$sSEPARATOR.' Page '.$iPage;}
$sOut .= ''."\n";
if ($sAUTHORS != ""){
$sOut .= ''."\n";
}
if ($sCOPYRIGHT != ''){
$sOut .= ''."\n";
}
$sOut .= ''."\n";
$sOut .= ''."\n";
$sOut .= $sStyle;
$sOut .= ''."\n";
$sOut .= "\n".''."\n";
if ($isPAGE_TITLE == 1){
$sOut .= ''.$sPAGE_TITLE;
if ($iPages > 1){$sOut .= ' '.$sSEPARATOR.' Page '.$iPage;}
$sOut .= '
'."\n";
}
// Lay up page navigation, if nescessary.
if ($iPages > 1){
$sOut .= '';
if ($iPage > 1){
$sOut .= '< Previous '.$sSEPARATOR.' ';
}
for ($c = 1; $c < $iPages+1; $c++){
if ( $c != $iPage){
$sOut .= ''.$c.'';
}else{
$sOut .= ''.$c.'';
}
if ($c != $iPages){$sOut .= ' '.$sSEPARATOR.' ';}
}
if ($iPage < $iPages){
$sOut .= ' '.$sSEPARATOR.' Next >';
}
// $sOut .= '
'."\n";
// if ($iPage > 1){
// $sOut .= '< Previous';
// }
//if ($iPage > 1 && $iPage < $iPages){$sOut .= ' '.$sSEPARATOR.' ';}
//if ($iPage < $iPages){
// $sOut .= 'Next >';
//}
$sOut .='
'."\n";
}
// Output the gallery table:
$isImage = true;
$iImage_count = 0;
$sOut .= ''."\n";
if ($iPages > 1){
$sOut .= '';
if ($iPage > 1){
$sOut .= '< Previous';
}
if ($iPage > 1 && $iPage < $iPages){$sOut .= ' '.$sSEPARATOR.' ';}
if ($iPage < $iPages){
$sOut .= 'Next >';
}
$sOut .='
'."\n";
}
$sOut .= '';
if ($sCOPYRIGHT != ''){
$sOut .= 'Copyright © '.$sCOPYRIGHT.'.
';
}
$sOut .= 'Gallery generated at '.date("H:i").' on '.date("Y-m-d").' with Pimp Version '.$VERSION.' using '.$iJPEG_QUALITY.'% JPEG compression.
'."\n";
if ($isXHTML_LOGO){
$sOut .='
'."\n";
}
$sOut .= ''."\n";
$sOut .= ''."\n";
// Do buffering and caching. index1.html, index2.html, etc....
ob_start();
echo $sOut;
$sCachefile = 'index'.$iPage.'.html';
$fp = fopen($sCachefile, 'w');
fwrite($fp, ob_get_contents());
fclose($fp);
ob_end_clean();
}
// ----------------------------------------------------
// Output the Index HTML page
// ----------------------------------------------------
$sOut = '';
$sOut .= '
'."\n";
$sOut .= ''."\n";
if ($sCOPYRIGHT != ''){
$sOut .= ''."\n";
}
$sOut .= "\n".''."\n";
$sOut .= ''.$sPAGE_TITLE.''."\n";
if ($isREDIRECT){
if (file_exists('index'.$iPages.'.html')) {
$sOut .= ''."\n";
}
}
if ($sAUTHORS != ""){
$sOut .= ''."\n";
}
if ($sCOPYRIGHT != ''){
$sOut .= ''."\n";
}
$sOut .= ''."\n";
$sOut .= ''."\n";
$sOut .= $sStyle_index;
$sOut .= ''."\n";
$sOut .= "\n".''."\n";
if ($isPAGE_TITLE == 1){
$sOut .= ''.$sPAGE_TITLE;
$sOut .= '
'."\n";
}
$sOut .= ''."\n";
for ($c = 1; $c < $iPages+1; $c++){
$sOut .= '- Gallery '.$c.'
'."\n";
}
$sOut .= '
'."\n";
if ($iPages == 0){
$sOut .= 'There are no image galleries to view.
The lack of pictures is most likely because there are no images in this directory from which to create the galleries.
'."\n";
}
$sOut .= '';
if ($sCOPYRIGHT != ''){
$sOut .= 'Copyright © '.$sCOPYRIGHT.'.
';
}
$sOut .= 'Gallery menu generated with Pimp Version '.$VERSION.'.
'."\n";
if ($isXHTML_LOGO){
$sOut .='
'."\n";
}
$sOut .= ''."\n";
$sOut .= ''."\n";
// Do buffering and caching of index.html
ob_start();
echo $sOut;
$sCachefile = 'index.html';
$fp = fopen($sCachefile, 'w');
fwrite($fp, ob_get_contents());
fclose($fp);
ob_end_clean();
// Finally chuck the browser out to the last HTML page created
if (file_exists($sCachefile)) {
include($sCachefile);
exit;
}
/*
Copyright (c) 2002 - 2004 Psand Ltd.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
?>