Want to greate a gallery from a directory full of pics?, need thumbnails on the fly? need it to update itself?
LOOK NO FURTHER
-----------------------------------------------------
Gallery.php
<?php
// made by Karv copyright him and the ones he ripped some code off
// cheers peeps - abuse this code as you like and feel free to name me in it
function getimgArray($dir,$sort='asort')
{
if ( is_dir($dir) ) {
$fd = @opendir($dir);
while ( ($part = @readdir($fd)) == TRUE ) {
clearstatcache();
if ($part != "." && $part != ".." && (ereg("\\.jpg\$",$part) || ereg("\\.jpeg\$",$part))) {
$dir_array[] = $part;
}
}
if($fd == TRUE) {
closedir($fd);
}
if (is_array($dir_array)) {
$sort($dir_array);
$dir_file_count = count($dir_array);
Return $dir_array;
} else {
Return FALSE;
}
} else {
Return FALSE;
}
}
$file_array = getimgArray('.','asort'); //set directory and sort type here
echo "<div align=\"center\"><table border=1 width=30%>";
$i=1;
foreach ($file_array as $file_name) {
if ($i%2) {
echo "<tr><td>";
echo "<div align=\"center\"><a href=$file_name><img src=\"image.php?file_name=$file_name\" border=0></div></a>";
echo "</td><td>";
} else {
echo "<div align=\"center\"><a href=$file_name><img src=\"image.php?file_name=$file_name\" border=0></div></a>";
echo "</td></tr>";
}
$i++;
}
echo "</table></div>";
unset($idx);
?>
--------------------------------------------------------
image.php
<?php
$src_img = ImageCreateFromJPEG($file_name); // need to add a $dir here if you need it outside the image folder
/* desired width of the thumbnail */
$picsize = 30; // sets the overall size of the thumb
/* grabs the height and width */
$new_w = imagesx($src_img);
$new_h = imagesy($src_img);
/* calculates aspect ratio */
$aspect_ratio = $new_h / $new_w;
/* sets new size */
$new_w = $picsize;
$new_h = abs($new_w * $aspect_ratio);
/* creates new image of that size */
$dst_img = imagecreate($new_w,$new_h);
/* copies resized portion of original image into new image */
imagecopyresized($dst_img,$src_img,0,0,0,0,$new_w,$new_h,imagesx($src_img),imagesy($src_img));
imageJPEG($dst_img);
?>
-------------------------------------------------------
have fun
Oh btw both these need to be in you image directory but I guess you guys are good enough to change that if needed, clues are (hopefully provided in the code) ***************************************
Party on, dudes!
LOOK NO FURTHER
-----------------------------------------------------
Gallery.php
<?php
// made by Karv copyright him and the ones he ripped some code off
// cheers peeps - abuse this code as you like and feel free to name me in it
function getimgArray($dir,$sort='asort')
{
if ( is_dir($dir) ) {
$fd = @opendir($dir);
while ( ($part = @readdir($fd)) == TRUE ) {
clearstatcache();
if ($part != "." && $part != ".." && (ereg("\\.jpg\$",$part) || ereg("\\.jpeg\$",$part))) {
$dir_array[] = $part;
}
}
if($fd == TRUE) {
closedir($fd);
}
if (is_array($dir_array)) {
$sort($dir_array);
$dir_file_count = count($dir_array);
Return $dir_array;
} else {
Return FALSE;
}
} else {
Return FALSE;
}
}
$file_array = getimgArray('.','asort'); //set directory and sort type here
echo "<div align=\"center\"><table border=1 width=30%>";
$i=1;
foreach ($file_array as $file_name) {
if ($i%2) {
echo "<tr><td>";
echo "<div align=\"center\"><a href=$file_name><img src=\"image.php?file_name=$file_name\" border=0></div></a>";
echo "</td><td>";
} else {
echo "<div align=\"center\"><a href=$file_name><img src=\"image.php?file_name=$file_name\" border=0></div></a>";
echo "</td></tr>";
}
$i++;
}
echo "</table></div>";
unset($idx);
?>
--------------------------------------------------------
image.php
<?php
$src_img = ImageCreateFromJPEG($file_name); // need to add a $dir here if you need it outside the image folder
/* desired width of the thumbnail */
$picsize = 30; // sets the overall size of the thumb
/* grabs the height and width */
$new_w = imagesx($src_img);
$new_h = imagesy($src_img);
/* calculates aspect ratio */
$aspect_ratio = $new_h / $new_w;
/* sets new size */
$new_w = $picsize;
$new_h = abs($new_w * $aspect_ratio);
/* creates new image of that size */
$dst_img = imagecreate($new_w,$new_h);
/* copies resized portion of original image into new image */
imagecopyresized($dst_img,$src_img,0,0,0,0,$new_w,$new_h,imagesx($src_img),imagesy($src_img));
imageJPEG($dst_img);
?>
-------------------------------------------------------
have fun
Oh btw both these need to be in you image directory but I guess you guys are good enough to change that if needed, clues are (hopefully provided in the code) ***************************************
Party on, dudes!