I now have GD enabled and have a random picture generator that is workinng properly. My problem now resides with trying to get my home page to reference the random image, one at a time per refresh or visit, and for them to be reduced to a much smaller size, somewhere around 250x 175 or so. On our home page it wil be like a picture of the moment etc..
Here is what I have so far. With the help of bradgrafelman davies. The randomizing page
www.egelands.com/randpic.php
code
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body><?php
/*
Random Image Generator
This script will scan a directory of your choosing, ignoring folders and
the dreaded Thumbs.db file and then return a randum image from the specified
folder. Easy to customise and use :-) I recommend using include() with this.
#
This code is free to use and written by Steven Davies. If you do use, please
leave the comment in a code so other web authors can find this site!
#
/
/ Customise this line to change to your images folder /
$dir = 'ce/trips/arizona/bigimages';
$dh = opendir($dir);
/ The following loop scans the directory specified ignoring folders and Thumbs.db /
while (false !== ($filename = readdir($dh))) {
if($filename == "Thumbs.db" || is_dir($filename)){
}else{
$tempArray = explode(".", $filename);
/ Add image file types in the code below */
if($tempArray[1] == "jpg" || $tempArray[1] == "gif" || $tempArray[1] == "png" || $tempArray[1] == "tif" || $tempArray[1] == "bmp"){
$files[] = $filename;
}
}
}
/ Generate a random number /
$nooffildi = count($files);
$nooffiles = ($nooffildi-1);
srand((double)microtime()*1000000);
$randnum = rand(0,$nooffiles);
/ print the result /
echo "<IMG SRC='$dir/$files[$randnum]' ALT='$files[$randnum]' BORDER='0'><br>";
echo "<!--Code Written By Steven Davies : www.phub.co.uk -->";
?>
</body>
</html>
Then for the "include ()" statement
www.egelands.com/test.php
code
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<? include('randpic.php'); ?>
</body>
</html>
Does anyone have any ideas on how to get these to a reduced size and even linkable back to the original sized image?
bradgrafelman had suggested something similar to the following (but this was before he saw the above code)
<?php
header('Content-type: image/jpeg');
// --- BEGIN CONFIGURATION ---
$path = 'images/';
$width = 175;
$height = 250;
// --- END CONFIGURATION ---
$files = @glob(realpath($path) . '/{.JPG,.jpg,.JPEG,.jpeg}', GLOB_BRACE);
if($files === FALSE) die();
$filename = $files[rand(0, count($files)-1)];
list($width_orig, $height_orig) = getimagesize($filename);
if ($width && ($width_orig < $height_orig)) {
$width = ($height / $height_orig) $width_orig;
} else {
$height = ($width / $width_orig) $height_orig;
}
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
imagejpeg($image_p, null, 100);
?>