Ver Mensaje Individual
  #1 (permalink)  
Antiguo 24/04/2011, 13:17
Avatar de pampa_
pampa_
 
Fecha de Ingreso: mayo-2006
Mensajes: 334
Antigüedad: 18 años, 9 meses
Puntos: 1
galeria imagenes php

Hola buenas, necesito hacer una galeria de imagenes para mi web. Buscando por google he encontrado una web con diferentes links a scripts ya hechos.

He cogido este.
[HIGHLIGHT="HTML"]
Código PHP:
Ver original
  1. <?php
  2.  
  3. // Root directory
  4. $root_dir = ".";
  5.  
  6. // Thumbnail Columns
  7. $columns = 5;
  8.  
  9. // Size of thumbnails in pixel
  10. $thumbwidth = 100;
  11.  
  12. // Slideshow 0=no 1=yes
  13. $slideshow = 0;
  14. ?>

<html>

<head>

<title>EasyGallery</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<meta name="author" content="Thomas Holtkötter">

<meta name="keywords" content="EasyGallery, WingNut, projects, freitagmorgen.de, www.freitagmorgen.de">

<style type="text/css">

BODY{margin:0 auto;}

*{margin:0;padding:0;}

.form{font-size:0.9em;margin:0 0 0 8px;}

.thumbnails{background-color:#FFF;border:#FFF 2px solid;}

.error{background-color:#999;width:100%;font-size:1.0em;font-weight:bold;padding:30px 0 30px 20px;}

.link{margin-left:11px;text-decoration:none;color:#666;font-size:0.8em;}

</style>

<script type="text/javascript" src="slimbox/js/jquery-1.3.2.min.js"></script>

<script type="text/javascript" src="slimbox/js/slimbox2.js"></script>

<link rel="stylesheet" href="slimbox/css/slimbox2.css" type="text/css" media="screen" />

</head>

<body>

Código PHP:
Ver original
  1. <?php
  2.  
  3. // --begin preprocessing
  4.  
  5. $phpself = $_SERVER['PHP_SELF'];
  6.  
  7. extract($_POST);
  8.  
  9.  
  10.  
  11. // filetypes
  12.  
  13. $filetypes = array("jpg", "jpeg");
  14.  
  15. $k = sizeof($filetypes);
  16.  
  17. for ($i=0; $i<$k; $i++)
  18.  
  19. {
  20.  
  21.   $filetypes[] = strtoupper($filetypes[$i]);
  22.  
  23. }
  24.  
  25.  
  26.  
  27. // extract local image folders
  28.  
  29. if (strpos($root_dir,'www')===0)
  30.  
  31. {
  32.  
  33.   $root_dir = 'http://'.$root_dir;
  34.  
  35. }
  36.  
  37. $local = parse_url($root_dir);
  38.  
  39. if (strpos($root_dir,'http://')===0)
  40.  
  41. {
  42.  
  43.   foreach (count_chars($phpself,1) as $i=>$val)
  44.  
  45.   {
  46.  
  47.     if (chr($i)=='/')
  48.  
  49.     {
  50.  
  51.       $root_dir = substr($local['path'],1);
  52.  
  53.       for ($j=1;$j<$val;$j++)
  54.  
  55.         $root_dir='../'.$root_dir;
  56.  
  57.     }
  58.  
  59.   }
  60.  
  61.   if (strpos($root_dir,$local['path'])===0)
  62.  
  63.   {
  64.  
  65.     $root_dir = ".";
  66.  
  67.   }
  68.  
  69. }
  70.  
  71.  
  72.  
  73. // scanning directory for folders and check if they contain image files
  74.  
  75. if (!is_dir($root_dir))
  76.  
  77. {
  78.  
  79.   printError("Couldn't find a root directory. Please specify a valid directory in EasyGallery.php.");
  80.  
  81. }
  82.  
  83. $root_handle = opendir($root_dir);
  84.  
  85. while ($dirname = readdir($root_handle))
  86.  
  87. {
  88.  
  89.   $var1 = strcmp($dirname,'.');
  90.  
  91.   $var2 = strcmp($dirname,'..');
  92.  
  93.   $var3 = is_dir($root_dir.'/'.$dirname);
  94.  
  95.   if (($var1!=0) && ($var2!=0) && ($var3==1))
  96.  
  97.   {
  98.  
  99.     $dir_handle = opendir($root_dir.'/'.$dirname);
  100.  
  101.     $postmp = 0;
  102.  
  103.     while ($filename = readdir($dir_handle))
  104.  
  105.     {
  106.  
  107.       for ($i=0;$i<sizeof($filetypes);$i++)
  108.  
  109.       {
  110.  
  111.         $postmp = strpos($filename, $filetypes[$i]);
  112.  
  113.         if ($postmp>0)
  114.  
  115.         {
  116.  
  117.           $folders[] = $root_dir.'/'.$dirname;
  118.  
  119.           break 2;
  120.  
  121.         }
  122.  
  123.       }
  124.  
  125.     }
  126.  
  127.     closedir($dir_handle);
  128.  
  129.   }
  130.  
  131. }
  132.  
  133. if (!$folders)
  134.  
  135. {
  136.  
  137.   printError("Searched folders don't contain any image! Please change the \$root_dir.");
  138.  
  139. }
  140.  
  141.  
  142.  
  143. // !!! if you don't want your folders in reverse order change rsort() to sort()
  144.  
  145. rsort($folders);
  146.  
  147.  
  148.  
  149. // set initial variable $ordner
  150.  
  151. if (!isset($ordner))
  152.  
  153.   $ordner = $folders[0];
  154.  
  155.  
  156.  
  157. // scanning directories for image files
  158.  
  159. if (is_dir($ordner)){
  160.  
  161.   $dir_handle = opendir($ordner);
  162.  
  163.   while ($filename = readdir($dir_handle))
  164.  
  165.   {
  166.  
  167.     for ($i=0; $i<sizeof($filetypes); $i++)
  168.  
  169.     {
  170.  
  171.       $pos = strpos($filename, $filetypes[$i]);
  172.  
  173.       $var1 = strcmp($filename,'.');
  174.  
  175.       $var2 = strcmp($filename,'..');
  176.  
  177.       $var3 = is_file($ordner.'/'.$filename);
  178.  
  179.       if (($var1 != 0) && ($var2 != 0) && ($var3 == 1) && ($pos > 0))
  180.  
  181.       {
  182.  
  183.         $files[] = $filename;
  184.  
  185.       }
  186.  
  187.       if ($filename=="thumbnails")
  188.  
  189.       {
  190.  
  191.         $thumbs = 1;
  192.  
  193.       }
  194.  
  195.     }
  196.  
  197.   }
  198.  
  199.   sort($files);
  200.  
  201.   $size = sizeof($files);
  202.  
  203.   closedir($dir_handle);
  204.  
  205.   closedir($root_handle);
  206.  
  207. }
  208.  
  209. else
  210.  
  211. {
  212.  
  213.   printError("No Folders found. Please copy your image folders to the location specified in the \$root_dir in EasyGallery.php.");
  214.  
  215. }
  216.  
  217. // --end preprocessing
  218.  
  219. ?>
  220.  
  221.  
  222.  
  223. <?php
  224.  
  225. // --begin form
  226.  
  227. echo "<div class=\"form\">\n";
  228.  
  229. echo "<form name=\"fotoalbum\" method=\"post\" action=\"$phpself\">\n";
  230.  
  231. echo "<select class=\"form\" name=\"ordner\" onchange=\"document.fotoalbum.submit();\">\n";
  232.  
  233. while ($folder = each($folders))
  234.  
  235. {
  236.  
  237.   if ($ordner == $folder["value"])
  238.  
  239.   {
  240.  
  241.     echo "<option selected value=\"$ordner\">";
  242.  
  243.   }
  244.  
  245.   else
  246.  
  247.   {
  248.  
  249.     echo "<option value=\"";
  250.  
  251.     echo $folder["value"];
  252.  
  253.     echo "\">";
  254.  
  255.   }
  256.  
  257.   $text = $folder["value"];
  258.  
  259.   while (strrpos($text,"/"))
  260.  
  261.   {
  262.  
  263.     $text = substr($text, strrpos($text,"/")+1);
  264.  
  265.   }
  266.  
  267.  
  268.   $text = str_replace("_", " ", $text); // Replace all _ with SPACE
  269.  
  270.   echo $text;
  271.  
  272.   echo " </option>\n";
  273.  
  274. }
  275.  
  276. echo "</select>\n";
  277.  
  278. echo "</form>\n";
  279.  
  280. echo "</div>\n";
  281.  
  282. // --end form
  283.  
  284.  
  285.  
  286. // --begin print images
  287.  
  288. echo "<div class=\"form\">";
  289.  
  290. $xpos=8;
  291.  
  292. $ypos=6;
  293.  
  294. $count = 0;
  295.  
  296. $newthumbs = false;
  297.  
  298. $divheight = ceil(count($files)/$columns) * ($thumbwidth+6) + 6;
  299.  
  300. echo "<table height=$divheight width=100% cellspacing=0 cellpadding=0><tr valign=top><td>\n";
  301.  
  302. for ($y=0;$y<count($files);$y++)
  303.  
  304. {
  305.  
  306.   $tn_src = $ordner."/thumbnails/tn_".$files[$count];
  307.  
  308.   if (file_exists($tn_src))
  309.  
  310.   {
  311.  
  312.     $image = GetImageSize($tn_src);
  313.  
  314.     $image[0] -= 8;
  315.  
  316.     $image[1] -= 8;
  317.  
  318.     if ($image[0]==$image[1]){}
  319.  
  320.     elseif ($image[0]<$image[1]) $xpos += intval(($image[1]-$image[0])/2);
  321.  
  322.     else $ypos += intval(($image[0]-$image[1])/2);
  323.  
  324.     echo "<div id=\"livethumbnail\" style=\"left:".$xpos."px; top:".$ypos."px; position:relative; zIndex=1;\">";
  325.  
  326.     if($slideshow!=1){
  327.  
  328.       echo "<a href=\"".$ordner."/".$files[$count]."\" rel=\"lightbox-\"".$ordner.">";
  329.  
  330.     }
  331.  
  332.     else{
  333.  
  334.       echo "<a href=\"".$ordner."/".$files[$count]."\" rel=\"lightbox-\"".$ordner.">";
  335.  
  336.     }
  337.  
  338.     echo "<img src=\"$tn_src\" class=\"thumbnails\" alt=\"$files[$count]\" style=\"width:$image[0]; height:$image[1]; left:0px; top:0px; position:absolute; zIndex=1;\"></a></div>\n";
  339.  
  340.     if ($image[0]==$image[1]){}
  341.  
  342.     elseif ($image[0]<$image[1]) $xpos -= intval(($image[1]-$image[0])/2);
  343.  
  344.     else $ypos -= intval(($image[0]-$image[1])/2);
  345.  
  346.   }
  347.  
  348.   else
  349.  
  350.   {
  351.  
  352.     $modules = get_loaded_extensions();
  353.  
  354.     if(!in_array("gd", $modules)){
  355.  
  356.       printError("Your webserver doesn't provide the use of the GD library, which is required to create thumbnails. Please create and add your thumbnails manually.");
  357.  
  358.     }
  359.  
  360.     if(createthumb($ordner,$files[$count],$thumbwidth))
  361.  
  362.     {
  363.  
  364.       echo "tn_$files[$count] created.<br>";
  365.  
  366.       $newthumbs = true;
  367.  
  368.     }
  369.  
  370.     else
  371.  
  372.     {
  373.  
  374.       printError("Thumbnail creation failed.");
  375.  
  376.     }
  377.  
  378.   }
  379.  
  380.   $count++;
  381.  
  382.   if($count%$columns==0)
  383.  
  384.   {
  385.  
  386.     $ypos += $thumbwidth+6;
  387.  
  388.     $xpos = 8;
  389.  
  390.   }
  391.  
  392.   else
  393.  
  394.   {
  395.  
  396.     $xpos += $thumbwidth+6;
  397.  
  398.   }
  399.  
  400. }
  401.  
  402. if($newthumbs)
  403.  
  404. {
  405.  
  406.   echo "<script>location.reload()</script>";
  407.  
  408. }
  409.  
  410. echo "</td></tr></table>\n";
  411.  
  412. echo '<p><a href=http://www.freitagmorgen.de class="link">EasyGallery</a></p>';
  413.  
  414. // dont even think about removing this link!
  415.  
  416. echo "</div>\n";
  417.  
  418. ?>


</body>


[HIGHLIGHT="PHP"]
<?php

function printError($text)

{

echo "<div class=\"error\">";

echo "<span class=\"content\">ERROR: $text</span>";

echo "</div>";

exit();

}



function createthumb($name,$file,$maxsize)

{

$maxsize += 8;

list($width, $height) = getimagesize("$name/$file");

$width = min($width, $height);

$tn = imagecreatetruecolor($maxsize, $maxsize);

$image = imagecreatefromjpeg("$name/$file");

imagecopyresampled($tn, $image, 0, 0, 0, 0, $maxsize, $maxsize, $width, $width);

if(!is_dir("$name/thumbnails"))

{

mkdir ("$name/thumbnails", 0777);

}

imagejpeg($tn, "$name/thumbnails/tn_$file", 90);

return true;

}

?>

<script>

<!--

var zoom = 4;

var speed = 4;

var real = 0;

var intervalIn;

var divs = document.getElementsByTagName('div');

for (var i=0; i<divs.length; i++)

{

if (divs[i].id == 'livethumbnail')

{

var myimg = divs[i].getElementsByTagName('img')[0];

myimg.smallSrc = myimg.getAttribute('src');

myimg.smallWidth = parseInt(myimg.getAttribute('width'));

myimg.smallHeight = parseInt(myimg.getAttribute('height'));

divs[i].onmouseover = scaleIn;

divs[i].onmouseout = scaleOut;

if (!myimg.smallWidth)

{