Foros del Web » Programando para Internet » PHP »

galeria imagenes php

Estas en el tema de galeria imagenes php en el foro de PHP en Foros del Web. 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. ...
  #1 (permalink)  
Antiguo 24/04/2011, 13:17
Avatar de pampa_  
Fecha de Ingreso: mayo-2006
Mensajes: 334
Antigüedad: 18 años
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)

{
  #2 (permalink)  
Antiguo 24/04/2011, 13:18
Avatar de pampa_  
Fecha de Ingreso: mayo-2006
Mensajes: 334
Antigüedad: 18 años
Puntos: 1
Respuesta: galeria imagenes php

<?php

if (isset($image)){

if ($image[0] > $image[1])

{

echo "myimg.smallWidth = $image[0];\n";

echo "myimg.smallHeight = $image[1];\n";

}

else

{

echo "myimg.smallWidth = $image[1];\n";

echo "myimg.smallHeight = $image[0];\n";

}

}

?>

real = 0;

}

else

{

real = 1;

}

}

}



function scaleIn()

{

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

myimg.style['zIndex'] = 100;

myimg.src = myimg.smallSrc;

var count = 0;

var real = 0;

intervalIn = window.setInterval(scaleStepIn, 1);

return false;



function scaleStepIn()

{

var widthIn = parseInt(myimg.style['width']);

var heightIn = parseInt(myimg.style['height']);

var topIn = parseInt(myimg.style['top']);

var leftIn = parseInt(myimg.style['left']);

if(widthIn >= heightIn) {

widthIn += speed;

heightIn += Math.floor(speed * (3/4));

topIn -= (Math.floor(speed * (3/8)));

leftIn -= (speed/2);

}

else

{

widthIn += Math.floor(speed * (3/4));

heightIn += speed;

topIn -= (speed/2);

leftIn -= (Math.floor(speed * (3/8)));

}

myimg.style['width'] = widthIn;

myimg.style['height'] = heightIn;

myimg.style['top'] = topIn;

myimg.style['left'] = leftIn;

count++;

if (count >= zoom)

window.clearInterval(intervalIn);

}

}

function scaleOut()

{

window.clearInterval(intervalIn);

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

myimg.src = myimg.smallSrc;

myimg.style['zIndex'] = 50;

var interval = window.setInterval(scaleStepOut, 1);

return false;


function scaleStepOut()

{

var width = parseInt(myimg.style['width']);

var height = parseInt(myimg.style['height']);

var top = parseInt(myimg.style['top']);

var left = parseInt(myimg.style['left']);

if(width >= height) {

width -= speed;

height -= Math.floor(speed * (3/4));

if(width < myimg.smallWidth + 4) {

myimg.style['width'] = myimg.smallWidth;

myimg.style['height'] = myimg.smallHeight;

myimg.style['top'] = 0;

myimg.style['left'] = 0;

myimg.style['zIndex'] = 1;

window.clearInterval(interval);

}

else{

myimg.style['width'] = width;

myimg.style['height'] = height;

myimg.style['left'] = left + (speed/2);

myimg.style['top'] = top + (Math.floor(speed * (3/8)));

}

}

else

{

width -= Math.floor(speed * (3/4));

height -= speed;

if(real==1)

{

if(width < myimg.smallWidth + 4)

{

myimg.style['width'] = myimg.smallWidth;

myimg.style['height'] = myimg.smallHeight;

myimg.style['top'] = 0;

myimg.style['left'] = 0;

myimg.style['zIndex'] = 1;

window.clearInterval(interval);

}

else{

myimg.style['width'] = width;

myimg.style['height'] = height;

myimg.style['top'] = top + (speed/2);

myimg.style['left'] = left + (Math.floor(speed * (3/8)));

}

}

else

{

if(height < myimg.smallWidth + 4)

{

myimg.style['width'] = myimg.smallHeight;

myimg.style['height'] = myimg.smallWidth;

myimg.style['top'] = 0;

myimg.style['left'] = 0;

myimg.style['zIndex'] = 1;

window.clearInterval(interval);

}

else{

myimg.style['width'] = width;

myimg.style['height'] = height;

myimg.style['top'] = top + (speed/2);

myimg.style['left'] = left + (Math.floor(speed * (3/8)));

}

}

}

}

}

//-->

</script>[/HIGHLIGHT]

</html>[/HIGHLIGHT]


Este codigo lo pongo en una nueva web .html quitandole las etiquetas de html... ya que esta nueva web la abro dentro de un div de mi index.php

El problema viene que el efecto que hace al pulsar encima de la imagen y superponertela en la web... no me lo hace sino que la imagen la abre en una web nueva.

Alguien sabria como adaptarlo?

Gracias si necesitais algo de mi codigo decidmelo.
  #3 (permalink)  
Antiguo 24/04/2011, 13:24
Avatar de dmm84  
Fecha de Ingreso: marzo-2011
Mensajes: 164
Antigüedad: 13 años, 1 mes
Puntos: 13
Respuesta: galeria imagenes php

no me acuerdo muy bien pero creo que es mediante un documento css
  #4 (permalink)  
Antiguo 24/04/2011, 16:04
Avatar de bioxido  
Fecha de Ingreso: diciembre-2008
Ubicación: $_SERVER['PHP_SELF']
Mensajes: 601
Antigüedad: 15 años, 5 meses
Puntos: 21
Respuesta: galeria imagenes php

Quita el tag target="_blank" de todos los links (<a></a>)

Suerte.
__________________
Si te ayude, el karma nunca sobra ;)
  #5 (permalink)  
Antiguo 25/04/2011, 06:44
Avatar de pampa_  
Fecha de Ingreso: mayo-2006
Mensajes: 334
Antigüedad: 18 años
Puntos: 1
Respuesta: galeria imagenes php

no tiene target="_blank"

alguien se le ocurre algo mas?
  #6 (permalink)  
Antiguo 25/04/2011, 07:08
Avatar de pampa_  
Fecha de Ingreso: mayo-2006
Mensajes: 334
Antigüedad: 18 años
Puntos: 1
Respuesta: galeria imagenes php

Código HTML:
Ver original
  1.     <div id="container">
  2.         <div id="topbar"><img src="images/titulo-informacion2.png"></img></div>
  3.         <div id="marquesina">Listado de Inmuebles</div>
  4.        
  5.         <div id="main">
  6.         <div id="menu-der">

Código PHP:
Ver original
  1. <?php
  2.         $link = mysql_connect("localhost", "root", "secreto");
  3.         mysql_select_db("bda_inmuebles", $link);
  4.        
  5.         $filtro='';
  6.         $tipo=$_POST['tipo'];
  7.         $gestion=$_POST['gestion'];
  8.         $preciomin=$_POST['minimo'];
  9.         $preciomax=$_POST['maximo'];
  10.         $localidad=$_POST['localidad'];
  11.        
  12.         //$result = mysql_query("SELECT tipo,localidad FROM inmuebles", $link);
  13.         //$result = mysql_query("SELECT * FROM inmuebles WHERE tipo='$tipo'", $link);      
  14.         $result = mysql_query("SELECT * FROM inmuebles WHERE $filtro", $link);
  15.        
  16.         // CODIGO PARA BUSCAR SI HAY UN ERROR EN LA CONSULTA
  17.         $error = mysql_error($link);  // $link es la variable de conexión
  18.            
  19.         if ($error!=null)
  20.         {
  21.             print("Ocurrio; el Siguiente Error:\n ".$error);
  22.             exit;
  23.         }
  24.         // FIN DE LA BUSQUEDA DE ERROR
  25.                    
  26.        
  27.        
  28.         echo '<table align="center" border="0" cellpadding="5px" cellspacing="0" width="500">';
  29.  
  30.         $contador =1;
  31.         $num_col=3;
  32.    
  33.         echo "<tr>";
  34.    
  35.         while ($row = mysql_fetch_row($result)){
  36.             $trans=array("&ntilde"=>"ñ"); //funcion para poder mostrar las ñ que en mysql son &ntilde
  37.             $row[4]=strtr($row[4],$trans);
  38.             $row[6]=strtr($row[6],$trans);
  39.             echo '<td align="left">';
  40.             ?>
Código HTML:
Ver original
  1. <a href="javascript:ajaxpage('slimbox2/example.html', 'menu-der');"><?php echo "<img src='$row[5]'></img>";?> </a>


Este seria el codigo de mi index.php y en este ultimo enlace me gustaria llamar a la pagina que contiene el efecto slimbox....
En este enlace esta otro efecto slimbox parecido al que he puesto... es lo mismo practicamente... http://www.digitalia.be/software/slimbox2

Etiquetas: galeria, imagenes
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 11:09.