[PHP] Photo Gallery v2

Only PHP & MySQL.

Moderator: DaD

[PHP] Photo Gallery v2

Postby NorbiX on Sat Jun 28, 2008 10:45 am

heyheyhey !!!

keit che hai combinato al sito? è una bellezza!

ti posto la galleria fotografica, ho aggiunto le funz per PNG e GIF (prima faceva solo il formato JPEG)

O.K., qui trovi un utilizzo della galleria suddetta http://norbix.altervista.org/quad_supply/

allora, qui il PHP (index.php)

Code: Select all
<div class = titlediv><span class = title>Photo Gallery</span></div>

<?php

$handle = opendir("images/");

/*while(($file = readdir($handle)) != false)
{
    if((strstr($file, ".jpg") != false) || (strstr($file, ".JPG") != false))
    {
         @$result = fopen("thumbs/$file", "r");
        if($result != NULL) fclose($result);
        else thumb_maker($file);
       
        echo "<a href = \"images/$file\"><image border = 0 src = \"thumbs/$file\"></a>";
    }
}*/

echo "<table align = center border = 0 cellpadding = 2>";
echo "<tr>";

$i = 0;

while(($file = readdir($handle)) != false)
{   
     if((strstr($file, ".jpg") != false) || (strstr($file, ".JPG") != false) || (strstr($file, ".jpgeg") != false) || (strstr($file, ".JPGEG") != false) || (strstr($file, ".png") != false) || (strstr($file, ".PNG") != false) || (strstr($file, ".gif") != false) || (strstr($file, ".GIF") != false))
     {
          if($i == 4)
          {
               echo "</tr><tr>";
               $i = 0;
          }

          @$result = fopen("thumbs/$file", "r");
          if($result != NULL) fclose($result);
          else thumb_maker($file);

          $res = get_image_size("images/$file");

          $size = filesize("images/$file") / 1024;
          $size = round($size, 0); # arrotondamento 0 cifre dopo la virgola

          #echo "<td><a href = \"images/$file\"><image border = 0 src = \"thumbs/$file\"></a></td>";
          echo "<td><table border = 0 width = 240><tr><center><font size = 2>$file - $res - $size"."kB</font></center></tr><tr><a href = \"images/$file\"><image border = 0 src = \"thumbs/$file\"></a></tr></table></td>";

          $i++;
     }
}

closedir($handle);

if($i % 4 != 0) echo "</tr>"; # scrive </tr> (fine riga) a meno che non sia stato appena scritto
echo "</table>";

function get_image_size($image)
{
     list($width, $height, $type, $attr) = getimagesize($image);

     return $width."x".$height;
}

function thumb_maker($image)
{
     list($width, $height, $type, $attr) = getimagesize("images/$image");

     $thumb = imagecreatetruecolor(240, 180);

     if((strstr($image, ".jpg") != false) || (strstr($image, ".JPG") != false) || (strstr($image, ".jpgeg") != false) || (strstr($image, ".JPGEG") != false))
     {
          $source = imagecreatefromjpeg("images/$image");
     }

     else if((strstr($image, ".png") != false) || (strstr($image, ".PNG") != false))
     {
          $source = imagecreatefrompng("images/$image");
     }

     else if((strstr($image, ".gif") != false) || (strstr($image, ".GIF") != false))
     {
          $source = imagecreatefromgif("images/$image");
     }   

     imagecopyresized($thumb, $source, 0, 0, 0, 0, 240, 180, $width, $height);

     if((strstr($image, ".jpg") != false) || (strstr($image, ".JPG") != false) || (strstr($image, ".jpgeg") != false) || (strstr($image, ".JPGEG") != false))
     {
          imagejpeg($thumb, "thumbs/$image", 75); # quality from 0 to 100
     }

     else if((strstr($image, ".png") != false) || (strstr($image, ".PNG") != false))
     {
          imagepng($thumb, "thumbs/$image", 7); # quality from 0 to 9
     }

     else if((strstr($image, ".gif") != false) || (strstr($image, ".GIF") != false))
     {
          imagegif($thumb, "thumbs/$image", 75); # quality from 0 to 100
     }
}

?>


e qui il CSS (power_amp.css)

Code: Select all
body
{
     color: #ffffff;
     background: #444444;
}

input
{
     color: #ffffff;
     background: #444444;

     width: 100%;
     text-align: center;

     border-width: 1px;
     border-color: #ffffff;

     margin-left: 1px;
     margin-right: 1px;
     margin-top: 1px;
     margin-bottom: 1px;
}

textarea
{
     color: #ffffff;
     background: #444444;
     /*text-align: center;*/
     border-width: 1px;
     border-color: #ffffff;
     margin-top: 1px;
     margin-bottom: 1px;
}

a
{
     text-decoration: none;
}

a:link
{
     color: #00ff00;
}

a:visited
{
     color: #00ff00;
}

a:hover
{
     color: #ffffff;
}

a:active
{
     color: #00ff00;
}

div
{
     width: 85%;
     text-align: center;

     margin-left: auto;
     margin-right: auto;
}

.titlediv
{
     margin-top: 25px;
     margin-bottom: 25px;
}

.title
{
     font-size: 35px;

     margin-left: auto;
     margin-right: auto;

     color: #ffffff;
}

.nickdiv
{
     text-align: left;
}

.fullwidth
{
     width: 100%
}

.textdiv
{
#    width: 100%;

     text-align: left;
}

.nickname
{
     color: #00ff00;

#    font-weight: bold;
}


ricordo che ci vogliono le cartelle images e thumbs, nella prima bisogna inserire le immagini, nella seconda saranno salvati i thumbs (anteprime)
#include <antisocialbastard>

anti-social_bastard_init(&norbix);
User avatar
NorbiX
Array[]
 
Posts: 722
Joined: Fri Jul 14, 2006 11:14 am
Location: Inside the N.A.K.

[PHP] Photo Gallery v2

Sponsor

Sponsor


Re: [PHP] Photo Gallery v2

Postby k8 on Sat Jun 28, 2008 3:33 pm

Perfetto lo uppo in homepage :D

edit:
comunque dovremmo riuscire a trovare delle funzioni per i file .tiff
Formato immagine sotto Mac OS X :)
Big-Bug cerca collaboratori.
Scrivete senza abbreviazioni e senza k, grazie.
k8
Admin
 
Posts: 2127
Joined: Tue Jun 06, 2006 4:00 pm


Return to PHP & MySQL

Who is online

Users browsing this forum: No registered users and 1 guest

cron