imagesx(): supplied argument is not a valid Image resource (CODE)
| From: | Robert Sossomon | Date: | Tue, 30 Nov 2004 19:05:22 +0000 |
| Subject: | imagesx(): supplied argument is not a valid Image resource (CODE) | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-203168@lists.php.net to get a copy of this message | ||
Here's the code for the page...
<?php
// this is the path of your files folder. Change 'pathofile'
$dir = "images/";
// this takes the files in the directory and puts them in an array
$array = array();
$handle = opendir($dir);
$extensoes = array("jpg", "png", "jpeg", "gif");
while ($file = readdir($handle))
{
for ($i = 0; $i < count($extensoes); $i++)
{
if (eregi("\.". $extensoes[$i] ."$", $file))
{
$array[] = $file;
}
}
}
closedir($handle);
sort($array);
reset($array);
// takes the objects in the array and randomizes them
$arrayobj = array_rand($array);
$random = $array[$arrayobj];
// this creates the path name to the random file
// $path becomes the path name (duh) for the file
$path = $dir . $random;
$width = imagesx($random)/4;
$height = imagesy($random)/4;
// this is set up as an <img> tag and will show a random image
print "<img src=\"$path\" height=\"$height\" width=\"$width\">\n";
?>
--
Robert Sossomon, Business and Technology Application Technician
4-H Youth Development Department
200 Ricks Hall, Campus Box 7606
N.C. State University
Raleigh NC 27695-7606
Phone: 919/515-8474
Fax: 919/515-7812
robert_sossomon@ncsu.edu