/* APA: Automatic Php Album (version 0.2, 2005-04-28) Copyright (c) 2005 Glenn ROLLAND. See the file COPYING for details on the GNU General Public License 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, 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. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ $config=array(); $comment=array(); $image=array(); $mydirectory= '.'; //directory in which images are fetched $config["image_regexp"]= "/\.(gif|png|jpe?g)$/"; $config["config_regexp"]= "/^\s*(.+?)\s*=\s*(.+?)\s*$/"; $config["apa_file"]=basename(__FILE__); $config["apa_version"]="0.2"; function loadConfig(){ global $config; $configName=str_replace(".php",".conf",$config["apa_file"]); if (! file_exists($configName)){ // create the configuration file $fh=fopen($configName,"w"); fwrite($fh,"\n"); fwrite($fh,"# album page title\n"); fwrite($fh,"album_title = Album generated by Automatic Php Album\n\n"); fwrite($fh,"# number of images per line (obsolete)\n"); fwrite($fh,"album_columns = 4\n\n"); fwrite($fh,"# thumbnail image quality (0: worst to 100:best)\n"); fwrite($fh,"thumb_quality = 75\n\n"); fwrite($fh,"# thumbnail image maximum size (width or lenght)\n"); fwrite($fh,"thumb_size = 160\n\n"); fwrite($fh,"# directory created to store thumbnail images\n"); fwrite($fh,"thumb_dir = thumb\n\n"); fwrite($fh,"# prefix for generated images\n"); fwrite($fh,"thumb_prefix = thumb_\n\n"); fwrite($fh,"# set apa_ready to '1' to be able to use album (obsolete)\n"); fwrite($fh,"ready = 0\n\n"); fclose($fh); loadConfig(); } else { // read the configuration file $content=""; $fh=fopen($configName,"r"); while(!feof($fh)){ $content.=fread($fh,8192); } fclose($fh); $confLines=explode("\n",$content); foreach ($confLines as $line ) { if (preg_match("/^\s*#/",$line)) { // skip } elseif (preg_match("/^\s*$/",$line)) { // skip } elseif (preg_match_all($config["config_regexp"],$line,$matches)){ $config[$matches[1][0]]=$matches[2][0]; } } } } function loadComment($mydirectory){ global $comment; global $config; $commentName=str_replace(".php",".info",$config["apa_file"]); if (! file_exists($commentName)){ // create the configuration file $fh=fopen($commentName,"w"); fwrite($fh,"\n"); $dirh=opendir($mydirectory); while ($currfile = readdir($dirh)){ if (preg_match($config["image_regexp"],strtolower($currfile))){ fwrite($fh,"# comment of file $currfile\n"); fwrite($fh,"$currfile = Image $currfile\n\n"); } } closedir($dirh); fclose($fh); loadComment($mydirectory); } else { // read the configuration file $content=""; $fh=fopen($commentName,"r"); while(!feof($fh)){ $content.=fread($fh,8192); } fclose($fh); $commentLines=explode("\n",$content); foreach ($commentLines as $line ) { $matches=array(); if (preg_match("/^\s*#/",$line)) { // skip } elseif (preg_match("/^\s*$/",$line)) { // skip } elseif (preg_match_all($config["config_regexp"],$line,$matches)){ $imagename=$matches[1][0]; $imagecomment=$matches[2][0]; if (preg_match($config["image_regexp"],strtolower($imagename))){ $comment[$matches[1][0]]=$matches[2][0]; } } } } } function displayThumb($imageNumber){ global $config; global $comment; global $image; $imageName=$image[$imageNumber]; $size = GetImageSize($imageName); $width=$size[0]; $height=$size[1]; $img=""; if ($width > $height){ $thumb_width = $config["thumb_size"]; $thumb_height = ($height * $config["thumb_size"]) / $width; } else { $thumb_width = ($width * $config["thumb_size"]) / $height; $thumb_height = $config["thumb_size"]; } $imageFormat = $size[2]; //1 = GIF, 2 = JPG, 3 = PNG, 5 = PSD, 6 = BMP $thumbName = "./" . $config["thumb_dir"] . "/" . $config["thumb_prefix"] . $imageName; if (! file_exists($thumbName)) { if ($imageFormat == 1){ //GIF $img = imagecreatefromgif($imageName); } elseif ($imageFormat == 2) { //JPG $img = imagecreatefromjpeg($imageName); } elseif ($imageFormat == 3) { //PNG $img = imagecreatefrompng($imageName); } else { $img=imagecreatetruecolor($thumb_width,$thumb_height); } if (!$img){ $thumbName = $imageName; } else { $img_thumb=imagecreatetruecolor($thumb_width,$thumb_height); imagecopyresampled($img_thumb,$img,0,0,0,0,$thumb_width,$thumb_height,$size[0],$size[1]); Imagejpeg($img_thumb, $thumbName, $config["thumb_quality"]); ImageDestroy($img_thumb); ImageDestroy($img); } } $urlThumbName = "./" . rawurlencode($config["thumb_dir"]) . "/" . rawurlencode($config["thumb_prefix"] . $imageName); echo "
"; echo "\n"; echo " $height){ echo " class=\"horizimg\" "; } echo " alt=\"Enlarge $imageName\" />\n"; echo "\n"; echo "
\n\n"; echo "".$comment[$imageName]."\n"; echo ""; if ($filenumber > 0) { echo "["; $prevnumber = $filenumber - 1; echo ""; echo " << Previous "; } else { echo "["; echo " << Previous "; } echo "]\n"; echo ""; echo "[ Main Page ]\n"; echo "\n"; if ($filenumber < count($image)-1) { echo "["; $nextnumber = $filenumber + 1; echo ""; echo " Next >> "; } else { echo "["; echo " Next >> \n"; } echo "]"; echo "
"; echo "\n"; echo $comment[$filename]; echo "
\n"; echo "\n";
echo "\n";
echo "
$filename
";
echo "
\n\n";
echo "\n\n";
}
}
loadConfig();
loadComment(".");
loadImages(".");
?>