Re: imagesx(): supplied argument is not a valid Image resource (CODE)
| From: | Chris | Date: | Tue, 30 Nov 2004 19:53:05 +0000 |
| Subject: | Re: imagesx(): supplied argument is not a valid Image resource (CODE) | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-203174@lists.php.net to get a copy of this message | ||
imagesx() requires an image resource , not a file path. so you'd need to use one of the imagecreatefrom* functions to create the resource.
But it looks like all you want is the width and height of an image.... If so use get imagesize() ( which *does* except a pathname, not a resource)
Chris
http://www.php.net/image
http://www.php.net/getimagesize
Robert Sossomon wrote:
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"; ?>