|
|
#1 | |
|
Registered User
Join Date: Jul 2005
Posts: 79
|
I used a PHP gallery tutorial a while back and found I could do more with it. At the moment it does exactly what I want it to do except for one cosmetic error which causes it to look dodgy.
www.harrydude.co.nr/gallerytest.php Have a look at that, at the far right of the thumbnails it tries to make an image out of the path to the gallery folder :\ its a small error but I can't get rid of it. ![]() I do have a work around but it requires me to have two seperate codes. (found on the actual gallery link on the site.) Here's the script: Code:
<?
$path = "gallery";
$files = "0";
$handle=opendir($path);
while ($file = readdir($handle)) {
if(!is_dir($path."/".$file) && $file != "." && $file!="..") {
$extension = explode (".", $file);
$extension_i = (count($extension) - 1);
$ext = $extension[$extension_i];
if($ext=="jpg"||$ext=="jpeg"||$ext=="JPG"||$ext=="JPEG") {
$images[$files] = $file;
$files++;
}
}
}
if(!$_GET["i"]) {
foreach($images as $image) {
$source = $path."/".$image;
$tsource = "thumbs/".$image;
$stsource = "small/".$image;
$thumbnail_h = "100";
$quality = "60";
$sthumbnail_h = "650";
$squality = "100";
if(file_exists($source)&&!file_exists($tsource)&&!file_exists($stsource)) {
$size = getimagesize($source);
$w = round($size[0]/($size[1]/$thumbnail_h));
$h = $thumbnail_h;
$resize = imagecreatetruecolor($w, $h);
$sw = round($size[0]/($size[1]/$sthumbnail_h));
$sh = $sthumbnail_h;
$sresize = imagecreatetruecolor($sw, $sh);
switch ($size['mime']) {
case 'image/jpeg':
$im = imagecreatefromjpeg($source);
imagecopyresampled($resize, $im, 0, 0, 0, 0, $w, $h, $size[0], $size[1]);
imagecopyresampled($sresize, $im, 0, 0, 0, 0, $sw, $sh, $size[0], $size[1]);
imagejpeg($resize, 'thumbs/'.$image, $quality);
imagejpeg($sresize, 'small/'.$image, $squality);
break;
case 'image/png':
$im = imagecreatefrompng($source);
imagecopyresampled($resize, $im, 0, 0, 0, 0, $w, $h, $size[0], $size[1]);
imagecopyresampled($sresize, $im, 0, 0, 0, 0, $sw, $sh, $size[0], $size[1]);
imagepng($resize, 'thumbs/'.$image, $quality);
imagepng($sresize, 'thumbs/'.$image, $squality);
break;
}
imagedestroy($im);
}
echo '<a href="?i='.$image.'"><img src="'.$tsource.'" border="0"></a>
';
}
}
echo '<a href="'.$path.'/'.$_GET["i"].'" target="_blank"><img src="small/'.$_GET["i"].'" border="0"></a>';
if($_GET["i"]&&file_exists($path.'/'.$_GET["i"]))
$id = array_search($_GET["i"],$images);
$files2 = $files-1;
if($id>"0"&&$id<$files2) {
$next_id = $id+1;
$prev_id = $id-1;
echo '<div align="center">';
echo '<br><a href="?i='.$images[$prev_id].'"><b>Previous</b></a><b>: :</b><a href="?i='.$images[$next_id].'"><b>Next</b></a><br><br><b><a href="gallerytest.php">Back to Main Gallery</a></b>';
}
if($id=="0") {
$next_id = "1";
echo '<br><b>Previous: :</b><a href="?i='.$images[$next_id].'"><b>Next</b></a><br><br><b><a href="gallerytest.php">Back to Main Gallery</a></b>';
}
if($id==$files2) {
$prev_id = $files2-1;
echo '<br><a href="?i='.$images[$prev_id].'"><b>Previous</b></a><b>: :Next</b><br><br><b><a href="gallerytest.php">Back to Main Gallery</a></b>';
}
echo '</div>';
?>
To test the gallery youreself make 3 folders on the server: 'gallery', 'thumbs' and 'small'. Save the script as 'gallerytest.php' and upload the images to the 'gallery' folder .Images are just tests btw. |
|
|
|
|
|
|
#2 | |
|
Registered User
Join Date: Jan 2005
Location: Amman, Jordan
Posts: 48
|
Didn't run it or anything, but try removing this line:
echo '<a href="'.$path.'/'.$_GET["i"].'" target="_blank"><img src="small/'.$_GET["i"].'" border="0"></a>'; |
|
|
|
|
|
|
#3 |
|
Join Date: Mar 2007
Posts: 183
|
try:
if ($_GET["i"]){echo '<a href="'.$path.'/'.$_GET["i"].'" target="_blank"><img src="small/'.$_GET["i"].'" border="0"></a>';}
__________________
CPU: i7 2600k @ 4.4Ghz GPU: GTX 560ti 2G SLI PPU: |
|
|
|
|
|
#4 | |
|
Registered User
Join Date: Jul 2005
Posts: 79
|
Omg cheers pross it actually worked
![]() |
|
|
|
|
|
|
#5 |
|
Join Date: Mar 2007
Posts: 183
|
of course it did
![]()
__________________
CPU: i7 2600k @ 4.4Ghz GPU: GTX 560ti 2G SLI PPU: |
|
|
|
![]() |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Planetside 2: A Gallery Of MAX, Comparisons, Tanks | News | Latest Tech And Game Headlines | 0 | 05-30-12 02:40 PM |