Re: imagesx(): supplied argument is not a valid Image resource (CODE)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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";
?>


-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux