You are here: Re: Building thumbnail page (mysql) « PHP Programming Language « IT news, forums, messages
Re: Building thumbnail page (mysql)

Posted by Krustov on 10/29/06 13:03

<comp.lang.php>
<Geoff Berrow>
<Sun, 29 Oct 2006 01:45:47 +0100>
<79u7k2p5g9uop3r6mrc5g4qhc2b11ru7fd@4ax.com>

> >I need some help (php rookie) to build a thumbnail page using php.
> >I'v a mysql database containing links to the original image files.
> >No thumbnails created so far.
> >
> >It would be nice when the thumbnail contains a link to the original file :-)
>
> Here's one without a database
>
> http://www.walkingoutdoors.co.uk/Geoff/gallery/
>
> http://www.walkingoutdoors.co.uk/Geoff/gallery/gallery.zip
>

The following doesnt need a database either , Although the user could
put the filenames into the database if they wanted there would be little
point as it scans the folder every time for new images & creates a
thumbnail if there isnt one already available .

- change the folder name

- change the number of columns (if wanted)

First draft php code - but seems to work ok .




<?php

$dir="test/images"; $columns=6;

$batman=0;

$joker=opendir($dir);
while (false!==($boywonder=readdir($joker)))
{
$files[]=$boywonder;
$batman=$batman+1;
}



$temp=0;
while ($temp<$batman)
{
$demo=$files[$temp];

$riddler=strlen($demo);
$penguin=substr($demo,$riddler-4,4);
$catwoman=substr($demo,$riddler-10,10);

$img_name="$dir" . "/" . "$demo";
$thumb_name=str_replace(".jpg","_thumb.jpg",$img_name);

if ($penguin==".jpg" && $catwoman<>"_thumb.jpg")
{

$pass=1;
$filename=$thumb_name;
if (!file_exists($filename)) {$pass=0;}

if ($pass==0)
{
$max_width=150; $max_height=80;
$size=GetImageSize($img_name);
$width_ratio=($size[0] / $max_width); $height_ratio=($size[1] /
$max_height);
if ($width_ratio>=$height_ratio) {$ratio=$width_ratio;} else {$ratio=
$height_ratio;}
$new_width=($size[0] / $ratio); $new_height=($size[1] / $ratio);
$src_img=ImageCreateFromJPEG($img_name);
$thumb=ImageCreateTrueColor($new_width,$new_height);
ImageCopyResampled($thumb,$src_img,0,0,0,0,($new_width-1),($new_height-
1),$size[0],$size[1]);
ImageJPEG($thumb,$thumb_name,100);
ImageDestroy($src_img);
ImageDestroy($thumb);
}

}

$temp=$temp+1;
}



$homer=0;

$joker=opendir($dir);
while (false!==($boywonder=readdir($joker)))
{
$marge[]=$boywonder;
$homer=$homer+1;
}

$lisa=0;

$temp=0;
while ($temp<$homer)
{
$demo=$marge[$temp];

$riddler=strlen($demo);
$penguin=substr($demo,$riddler-4,4);
$catwoman=substr($demo,$riddler-10,10);

if ($catwoman=="_thumb.jpg")
{
$thumb_name="$dir" . "/" . "$demo";
$img_name=str_replace("_thumb.jpg",".jpg",$thumb_name);
$millhouse[$lisa]=$thumb_name;
$diamondjoe[$lisa]=$img_name;
$lisa=$lisa+1;
}

$temp=$temp+1;
}

?>

<?php

print "<table border=0 cellspacing=5 cellpadding=0 align=center>";

$loopy=0;

while ($loopy<$lisa)
{

print "<tr valign=top>";

$tempxx=0;
while ($tempxx<$columns)
{

if ($loopy<$lisa)
{
$size=GetImageSize($millhouse[$loopy]);
print "<td><a href=$diamondjoe[$loopy]><img src=$millhouse[$loopy]
width=$size[0] height=$size[1] border=0></a><br></td>";
}

$tempxx=$tempxx+1;
$loopy=$loopy+1;
}

print "</tr>";

}


print "</table>";

?>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация