Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,227 members, 7,818,770 topics. Date: Monday, 06 May 2024 at 01:52 AM

Next Home Work For Students: A Plain Php Photo Gallery - See Screenshot. - Webmasters - Nairaland

Nairaland Forum / Science/Technology / Webmasters / Next Home Work For Students: A Plain Php Photo Gallery - See Screenshot. (704 Views)

LOL Screenshot Of Old Yahoo Portal / What Do You Think About My Photo Gallery Design / Photo Gallery/slideshow: Just The Way I Like It (2) (3) (4)

(1) (Reply) (Go Down)

Next Home Work For Students: A Plain Php Photo Gallery - See Screenshot. by Nobody: 9:30pm On Feb 26, 2009
Lemme give out this home work. Just write a simple php script to display a photo gallery like this:
Actually this one will automatically trim the photo to size without loosing aspect ratio.

I assume this one is easier than the previous question or i am mistaken?

Re: Next Home Work For Students: A Plain Php Photo Gallery - See Screenshot. by Nobody: 9:34pm On Feb 27, 2009
Since there is no reply, only one choice left now - i will have to disapoint by not saying anything - obviously no one else is interested.
Re: Next Home Work For Students: A Plain Php Photo Gallery - See Screenshot. by cyberomin(m): 12:05pm On Feb 28, 2009
Egbon noooooo, abeg continue am, i dey interested.
Re: Next Home Work For Students: A Plain Php Photo Gallery - See Screenshot. by Nobody: 12:39pm On Feb 28, 2009
The solution will be found on here:

demo link: http://mwebng.net/demos/slideshow/
download: http://mwebng.net/demos/slideshow.zip

Explanation:
2 main scripts there:

index.php - scans the folder and view the files
<div align="left" style="margin-left:10px;">
<?php
$folder="./";

$max_rows=4;

function getext($file) {$pos = strrpos($file, "."wink;
if ($pos === false) { $file=$file;} else {$file=substr($file,$pos+1,strlen($file));}
return strtolower($file);
}

function is_image($file) {
if(!is_file($file)) {return false;}
$ext=getext($file);

if($ext=="jpg"||$ext=="gif"||$ext=="png"wink {return true;}

return false;
}

function render($image,$folder) {
$date=date ("M d, Y", filemtime("$folder$image"wink);

print<<<end
<td>
<table align="center" style="width:133px;height:133px;border:1px solid #000000;font:11px tahoma" cellspacing=0 cellpadding=0 bgcolor="#ffffff">
<tr><td align="center" valign="middle" height=133 style="border-bottom:1px solid #000000">
<img src="image.php?f=$folder&i=$image&s=1" align="middle">
</td>
</tr>
<tr><td align="center" bgcolor="#ceceff" style="padding-top:1px;padding-bottom:1px;">
<font color="blue">Added: $date</font>
</td></tr>
</table>
</td>
end;
}

$list_ignore = array ('.',', ','.db','.inf','phpmyadmin','sqlitemanager');
$handle=opendir("$folder"wink;
$files=array();
while ($file = readdir($handle)) {
  if (is_image("$folder".$file) && !in_array($file,$list_ignore)) {   
  $files[]=$file;
  }
}
closedir($handle);
sort($files);

$count=0;
print<<<end
<table cellspacing=14>
end;
foreach($files as $file) {$count++;
if($count==1) {echo "<tr>";}
  render("$file","$folder"wink;
if($count==$max_rows) {echo "</tr>";$count=0;}
}

print<<<end
</table>
end;

?>
</div>



image.php - an image rendered
<?php
session_start();
header("Cache-Control: no-cache, must-revalidate"wink; // HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"wink; // Date in the past
header("Content-type: image/jpeg"wink;


$filename="./".$_REQUEST['f'].$_REQUEST['i'];

switch($_REQUEST['s']) {
case "1":
$width=133;$height=133;
break;
default:
$width=100;$height=100;
break;
}

// Get new dimensions
list($width_orig, $height_orig) = getimagesize($filename);

if($width_orig==0) {

$im = @imagecreatetruecolor($width, $height);
$bg = imagecolorallocate($im, 255, 255, 255);
$textcolor = imagecolorallocate($im, 255, 255, 255);

imagestring($im, 1, 30, 5,  "Invalid Image", $textcolor);
imagejpeg($im);
imagedestroy($im);

die();
}

//crop
if ($width && ($width_orig < $height_orig)) {
    $width = ($height / $height_orig) * $width_orig;
} else {
    $height = ($width / $width_orig) * $height_orig;
}


$im2 = imagecreatetruecolor($width, $height);
$im = imagecreatefromjpeg($filename);

imagecopyresampled($im2, $im, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); 
imagejpeg($im2, null, 100);

imagedestroy($im);
imagedestroy($im2);
?>



I am not sure if that is well optimized - copied directly from my old library.

Well, as alwayz questions are welcomed from those want to learn to make something better.


Ehm, a number of techniques were employed in this solution such as image resizing,

(1) (Reply)

Great Looking Minisite - Step By Step / I Need A Credible Partner In This Multimillion Naira Website Deal! / Steve Jobs Steps Down From Ceo Of Apple

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 21
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.